Here you can find the source of printNode(OutputStream out, Node node, boolean prettyPrint, boolean includeXmlDeclaration)
public static void printNode(OutputStream out, Node node, boolean prettyPrint, boolean includeXmlDeclaration)
//package com.java2s; import org.w3c.dom.*; import javax.xml.transform.*; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import java.io.OutputStream; public class Main { private static final TransformerFactory tFactory = TransformerFactory .newInstance(); public static void printNode(OutputStream out, Node node, boolean prettyPrint, boolean includeXmlDeclaration) { try {/*from ww w.j a v a 2 s . c om*/ Transformer serializer = tFactory.newTransformer(); if (prettyPrint) { //Setup indenting to "pretty print" serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.setOutputProperty( "{http://xml.apache.org/xslt}indent-amount", "2"); } if (!includeXmlDeclaration) { serializer.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "yes"); } DOMSource xmlSource = new DOMSource(node); StreamResult outputTarget = new StreamResult(out); serializer.transform(xmlSource, outputTarget); } catch (TransformerException e) { throw new RuntimeException(e); } } }