List of utility methods to do XML Document to String
String | xmlDocumentToString(final Document document) Generates a String that is populated with the textual representation of the XML DOM of the given Document. final DOMImplementationLS domImplementation = (DOMImplementationLS) document.getImplementation(); LSSerializer lsSerializer = domImplementation.createLSSerializer(); return lsSerializer.writeToString(document); |
String | xmlDocumentToString(Node d) Converts an XML document or node to an equivalent string. StringWriter writer = new StringWriter(); Transformer t = TransformerFactory.newInstance().newTransformer(); t.transform(new DOMSource(d), new StreamResult(writer)); return writer.toString(); |
String | xmlDOMDocumentToString(Document doc) Convert XML DOM document to a XML string representation if (doc == null) { throw new RuntimeException("No XML DOM document (null)!"); StringWriter stringWriter = new StringWriter(); String strDoc = null; try { StreamResult streamResult = new StreamResult(stringWriter); TransformerFactory transformerFactory = TransformerFactory.newInstance(); ... |
String | XMLDOMtoString(Document document) XMLDO Mto String String out = null; try { TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); StringWriter writer = new StringWriter(); Result result = new StreamResult(writer); Source source = new DOMSource(document); transformer.transform(source, result); ... |
void | xmlToFile(Document doc, String fileNameToWrite) xml To File DOMSource domSource = new DOMSource(doc); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(fileNameToWrite))); StreamResult streamResult = new StreamResult(out); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.transform(domSource, streamResult); |
String | xmlToString(Document doc) xml To String try { Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); StreamResult result = new StreamResult(new StringWriter()); DOMSource source = new DOMSource(doc); transformer.transform(source, result); return result.getWriter().toString(); } catch (TransformerException ex) { ... |
String | XMLtoString(Document doc) XM Lto String String output = null; try { TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(doc), new StreamResult(writer)); output = writer.getBuffer().toString().replaceAll("\n|\r", ""); ... |
String | xmlToString(Document doc) Will get an XML Document as a String final Transformer transformer = TransformerFactory.newInstance().newTransformer(); final StreamResult result = new StreamResult(new StringWriter()); final DOMSource source = new DOMSource(doc); transformer.transform(source, result); return result.getWriter().toString(); |
String | xmlToString(Document document) Convert XML Document to its string representation. if (transformer == null) { throw new Exception("Transformer is null"); Source xmlSource = new DOMSource(document); StringWriter stringWriter = new StringWriter(); Result result = new StreamResult(stringWriter); transformer.transform(xmlSource, result); return stringWriter.toString(); ... |
String | xmlToString(Document xml) Converts a DOM Tree to a String. try { TransformerFactory f = TransformerFactory.newInstance(); StringWriter writer = new StringWriter(); Transformer t = f.newTransformer(); DOMSource src = new DOMSource(xml); StreamResult result = new StreamResult(writer); t.transform(src, result); return writer.toString(); ... |