Here you can find the source of prettyPrint(Document doc, String programID, String xmlTraDestinationFolderPath)
public static final void prettyPrint(Document doc, String programID, String xmlTraDestinationFolderPath) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileWriter; import java.io.Writer; import javax.xml.transform.OutputKeys; 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 final void prettyPrint(Document doc, String programID, String xmlTraDestinationFolderPath) throws Exception { Transformer tf = TransformerFactory.newInstance().newTransformer(); tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); tf.setOutputProperty(OutputKeys.INDENT, "yes"); Writer out = new FileWriter(new File(xmlTraDestinationFolderPath + programID.replaceAll("_", "-") + ".xml")); tf.transform(new DOMSource(doc), new StreamResult(out)); }// w w w. j av a 2 s . c om }