Here you can find the source of printXmlDocument(Document doc)
public static void printXmlDocument(Document doc)
//package com.java2s; //License from project: Open Source License import java.io.StringWriter; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; public class Main { public static void printXmlDocument(Document doc) { System.out.println(xmlDocumentToString(doc)); }// w ww . j ava 2 s . c o m public static String xmlDocumentToString(Document doc) { try { DOMSource domSource = new DOMSource(doc); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.transform(domSource, result); return writer.toString(); } catch (TransformerException ex) { ex.printStackTrace(); return null; } } }