Java Utililty Methods XML Document Print

List of utility methods to do XML Document Print

Description

The list of methods to do XML Document Print are organized into topic(s).

Method

voidprintXML(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", "");
voidprintXml(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));
voidprintXmlDocument(Document doc)
print Xml Document
System.out.println(xmlDocumentToString(doc));
StringprintXMLDocument(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);
...
voidprintXMLFormat(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);
...