/** * @since 1.4 */ public XomReader(Document document, NameCoder nameCoder) { super(document.getRootElement(), nameCoder); }
/** * @since 1.2 * @deprecated As of 1.4 use {@link XomReader#XomReader(Element, NameCoder)} instead. */ public XomReader(Document document, XmlFriendlyReplacer replacer) { this(document.getRootElement(), (NameCoder)replacer); }
public XomReader(Document document) { super(document.getRootElement()); }
Builder parser = new Builder(); StringReader in = new StringReader(xml); docElem = parser.build(in).getRootElement(); } catch (ParsingException | IOException e) { throw new RuntimeException(String.format("error:\n%s\ninput:\n%s", e, xml));
public static List<Request> getRequestCollectionFromXMLFile(final File f) throws IOException, XMLException { XmlPersistenceRead xUtlRead = new XmlPersistenceRead(); List<Request> out = new ArrayList<>(); Document doc = xUtlRead.getDocumentFromFile(f); Element eRoot = doc.getRootElement(); if(!"request-collection".equals(eRoot.getLocalName())) { throw new XMLException("Expecting root element <request-collection>, but found: " + eRoot.getLocalName()); } final String version = eRoot.getAttributeValue("version"); try { Versions.versionValidCheck(version); } catch(Versions.VersionValidationException ex) { throw new XMLException(ex); } xUtlRead.setReadVersion(version); Elements eRequests = doc.getRootElement().getChildElements(); for(int i=0; i<eRequests.size(); i++) { Element eRequest = eRequests.get(i); Request req = xUtlRead.getRequestBean(eRequest); out.add(req); } return out; }
Element rootNode = doc.getRootElement();
protected Request xml2Request(final Document doc) throws MalformedURLException, XMLException { // get the rootNode Element rootNode = doc.getRootElement(); if (!"rest-client".equals(rootNode.getQualifiedName())) { throw new XMLException("Root node is not <rest-client>"); } // checking correct rest version final String rcVersion = rootNode.getAttributeValue("version"); try { Versions.versionValidCheck(rcVersion); } catch(Versions.VersionValidationException ex) { throw new XMLException(ex); } readVersion = rcVersion; // if more than two request element is present then throw the exception if (rootNode.getChildElements().size() != 1) { throw new XMLException("There can be only one child node for root node: <request>"); } // minimum one request element is present in xml if (rootNode.getFirstChildElement("request") == null) { throw new XMLException("The child node of <rest-client> should be <request>"); } Element requestNode = rootNode.getFirstChildElement("request"); return getRequestBean(requestNode); }
/** * @since 1.4 */ public XomReader(final Document document, final NameCoder nameCoder) { super(document.getRootElement(), nameCoder); }
@Override public void staxSource(XMLStreamReader streamReader) throws XMLStreamException { Document document = StaxStreamConverter.convert(streamReader); element = document.getRootElement(); }
/** * @since 1.2 * @deprecated As of 1.4 use {@link XomReader#XomReader(Element, NameCoder)} instead. */ public XomReader(Document document, XmlFriendlyReplacer replacer) { this(document.getRootElement(), (NameCoder)replacer); }
/** * @since 1.4 */ public XomReader(Document document, NameCoder nameCoder) { super(document.getRootElement(), nameCoder); }
/** * @since 1.2 * @deprecated As of 1.4 use {@link XomReader#XomReader(Element, NameCoder)} instead. */ @Deprecated public XomReader(final Document document, final XmlFriendlyReplacer replacer) { this(document.getRootElement(), (NameCoder)replacer); }
Nodes getDocumentFragment() { Element rootElt = document.getRootElement(); Nodes rv = rootElt.removeChildren(); document = null; return rv; }
public static CMLElement parseQuietlyIntoCML(File xmlFile) { CMLElement rootElement = null; try { rootElement = (CMLElement) new CMLBuilder().build(xmlFile).getRootElement(); } catch (Exception e) { throw new RuntimeException("cannot parse/read file: "+xmlFile.getAbsolutePath(), e); } return rootElement; }
@Override public void streamSource(Reader reader) throws IOException { try { Builder builder = new Builder(); Document document = builder.build(reader); element = document.getRootElement(); } catch (ParsingException ex) { throw new XomParsingException(ex); } }
@Override public void streamSource(Reader reader) throws IOException { try { Builder builder = new Builder(); Document document = builder.build(reader); element = document.getRootElement(); } catch (ParsingException ex) { throw new XomParsingException(ex); } }
public People(String fileName) throws Exception { Document doc = new Builder().build(new File(fileName)); Elements elements = doc.getRootElement().getChildElements(); for(int i = 0; i < elements.size(); i++) add(new APerson(elements.get(i))); } public static void
public void beforeParsing(Document document) { Element html = document.getRootElement(); Element head = html.getFirstChildElement("head"); Check.notNull(head, "<head> section is missing from document"); Element script = new Element("script"); script.addAttribute(new Attribute("type", "text/javascript") ); script.appendChild(javaScript); head.insertChild(script, 0); } }
public void beforeParsing(Document document) { nu.xom.Element html = document.getRootElement(); nu.xom.Element head = html.getFirstChildElement("head"); Check.notNull(head, "<head> section is missing from document"); script = new nu.xom.Element("script"); script.addAttribute(new Attribute("type", "text/javascript")); // Fix for Issue #26: Strict XHTML DTD requires an explicit end tag for <script> element // Thanks to Matthias Schwegler for reporting and supplying a fix for this. script.appendChild(""); head.appendChild(script); }
public void beforeParsing(Document document) { nu.xom.Element html = document.getRootElement(); nu.xom.Element head = html.getFirstChildElement("head"); Check.notNull(head, "<head> section is missing from document"); link = new nu.xom.Element("link"); link.addAttribute(new Attribute("type", "text/css")); link.addAttribute(new Attribute("rel", "stylesheet")); head.appendChild(link); }