List of utility methods to do XML Document Parse
Document | parseDocument(InputStream is) Parses the document. DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
return builder.parse(is);
|
Document | parseDocument(InputStream is) Parses the given input stream as XML and returns the corresponding DOM document. getImplementation(); DOMImplementationLS implLS = (DOMImplementationLS) impl; LSInput input = implLS.createLSInput(); input.setByteStream(is); LSParser builder = implLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null); DOMConfiguration config = builder.getDomConfig(); config.setParameter("comments", false); config.setParameter("element-content-whitespace", false); ... |
Document | parseDocument(Path xmlPath) parse Document File fXmlFile = new File(xmlPath.toUri()); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); return dBuilder.parse(fXmlFile); |
Document | parseDocument(Reader reader) parse Document DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); try { return factory.newDocumentBuilder().parse(new InputSource(reader)); } catch (ParserConfigurationException | SAXException e) { throw new IOException(e); |
Document | parseDocument(String docText) A wrapper function to parse XML represented by a string. DocumentBuilder dbld = DocumentBuilderFactory.newInstance().newDocumentBuilder(); return dbld.parse(new InputSource(new StringReader(docText))); |
Document | parseDocument(String documentString) parse Document DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(true); DocumentBuilder domBuilder = domFactory.newDocumentBuilder(); StringReader stringReader = new StringReader(documentString); InputSource inputSource = new InputSource(stringReader); return domBuilder.parse(inputSource); |
Document | parseDocument(String documentString) Parses the given string to a DOM object. try { DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(true); DocumentBuilder domBuilder = domFactory.newDocumentBuilder(); StringReader stringReader = new StringReader(documentString); InputSource inputSource = new InputSource(stringReader); return domBuilder.parse(inputSource); } catch (IOException e) { ... |
Document | parseDocument(String path) Parses document from specified location and returns it. try { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); return documentBuilderFactory.newDocumentBuilder().parse(new File(path)); } catch (ParserConfigurationException | IOException | SAXException e) { throw new RuntimeException(e); |
Document | parseDocument(String xmlString) parse Document DocumentBuilder builder = builderFactory.newDocumentBuilder(); return builder.parse(new ByteArrayInputStream(xmlString.getBytes())); |
String | parseDocumentIntoStringXML(Document document) Converts a Document into String representation UTF-8 conversion StringWriter output = new StringWriter(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(new DOMSource(document), new StreamResult(output)); String newObjectResourceXML = output.toString(); return newObjectResourceXML; |