Here you can find the source of printXml(Document xml, Writer out)
public static void printXml(Document xml, Writer out) throws TransformerException, UnsupportedEncodingException
//package com.java2s; //License from project: GNU General Public License import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.io.Writer; import javax.xml.transform.OutputKeys; 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 printXml(Document xml, Writer out) throws TransformerException, UnsupportedEncodingException { Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(new DOMSource(xml), new StreamResult(out)); }/*from ww w . j a v a 2 s. co m*/ public static void printXml(Document response, OutputStream out) throws UnsupportedEncodingException, TransformerException { printXml(response, new OutputStreamWriter(out)); } }