Here you can find the source of printDoc(Document doc)
public static void printDoc(Document doc)
//package com.java2s; import javax.xml.transform.Transformer; 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 printDoc(Document doc) { try {//from w w w . java2 s .c o m TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); t.transform(new DOMSource(doc), new StreamResult(System.out)); } catch (Exception ex) { new RuntimeException(ex); } } }