List of utility methods to do XML String to Document
Document | strToDocument(final String strXml) str To Document DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); try { DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(new InputSource(new StringReader(strXml))); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { ... |
Element | strToXML(final Document doc, final String namespaceURI, final String qname, final String str) returns XML representation of a string, with specified XML node name if (str == null ) { return null; final Element xml = doc.createElementNS(namespaceURI, qname); xml.appendChild(doc.createTextNode(str)); return xml; |
Document | toDocument(String content) to Document DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); return content == null ? null : db.parse(new InputSource(new StringReader(content))); |
Document | toDocument(String input) to Document InputStream is = new ByteArrayInputStream(input.getBytes("UTF-8")); Document document = toDocument(is); return document; |
Document | toDocument(String s) to Document return (toDocument(s.getBytes()));
|
Document | toDocument(String str) Transform string to XML document. return builders.get().parse(new ByteArrayInputStream(str.getBytes("UTF-8"))); |
Document | toDocument(String string) Parses XML document DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(new InputSource(new StringReader(string))); |
Document | toDocument(String xml) to Document return toDocument(xml, false);
|
Document | toDocument(String xml) Method reads in the xml and returns the top level document. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource source = new InputSource(new StringReader(xml)); return builder.parse(source); |
Document | toXmlDocument(final InputStream inputStream, final String path) to Xml Document try { final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); final DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); return documentBuilder.parse(inputStream); } catch (final ParserConfigurationException ex) { throw new RuntimeException("Unable to read classpath resource: " + path, ex); } catch (final SAXException ex) { throw new RuntimeException("Unable to read classpath resource: " + path, ex); ... |