Here you can find the source of prettyXmlPrint(Node xml, OutputStream out)
public static final void prettyXmlPrint(Node xml, OutputStream out) throws TransformerConfigurationException, TransformerFactoryConfigurationError, TransformerException
//package com.java2s; /******************************************************************************* * I N T E L C O R P O R A T I O N * /*w w w .j av a 2 s . c o m*/ * Functional Group: Fabric Viewer Application * * File Name: AppDataUtils.java * * Archive Source: $Source$ * * Archive Log: $Log$ * Archive Log: Revision 1.18 2015/08/17 18:49:06 jijunwan * Archive Log: PR 129983 - Need to change file header's copyright text to BSD license txt * Archive Log: - change backend files' headers * Archive Log: * Archive Log: Revision 1.17 2015/06/10 19:36:45 jijunwan * Archive Log: PR 129153 - Some old files have no proper file header. They cannot record change logs. * Archive Log: - wrote a tool to check and insert file header * Archive Log: - applied on backend files * Archive Log: * * Overview: * * @author: Fernando Fernandez * ******************************************************************************/ import java.io.OutputStream; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.TransformerFactoryConfigurationError; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Node; public class Main { public static final void prettyXmlPrint(Node xml, OutputStream out) throws TransformerConfigurationException, TransformerFactoryConfigurationError, TransformerException { Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.transform(new DOMSource(xml), new StreamResult(out)); } }