Here you can find the source of printDOM(Node node, OutputStream out, String encoding)
public static void printDOM(Node node, OutputStream out, String encoding) throws TransformerException
//package com.java2s; //License from project: Apache License import java.io.OutputStream; 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.Node; public class Main { public static void printDOM(Node node, OutputStream out, String encoding) throws TransformerException { TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer;/*w w w . jav a2s .co m*/ transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, encoding); transformer.setOutputProperty( "{http://xml.apache.org/xslt}indent-amount", "4"); transformer.transform(new DOMSource(node), new StreamResult(out)); } public static void printDOM(Node node, OutputStream out) { try { printDOM(node, out, "UTF-8"); } catch (TransformerException e) { throw new RuntimeException(e); } } }