List of utility methods to do XML Document Print
void | printXML(Document doc) print XML 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)); String output = writer.getBuffer().toString().replaceAll("\n|\r", ""); |
void | printXml(Document xml, Writer out) print Xml Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(new DOMSource(xml), new StreamResult(out)); |
void | printXmlDocument(Document doc) print Xml Document System.out.println(xmlDocumentToString(doc)); |
String | printXMLDocument(Document document) print XML Document String XMLString = new String(); StringWriter stringWriter = new StringWriter(); DOMSource source = new DOMSource(document); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer; try { transformer = transformerFactory.newTransformer(); StreamResult result = new StreamResult(stringWriter); ... |
void | printXMLFormat(Document document) Print the indented document. TransformerFactory transformerFactory = TransformerFactory.newInstance(); transformerFactory.setAttribute("indent-number", 4); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); StreamResult streamResult = new StreamResult(); DOMSource source = new DOMSource(document); transformer.transform(source, streamResult); ... |