Here you can find the source of saveReportToFile(Node node, String documentFileName)
public static void saveReportToFile(Node node, String documentFileName)
//package com.java2s; //License from project: Apache License import java.io.File; 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 saveReportToFile(Node node, String documentFileName) { // StringWriter writer = new StringWriter(); // StreamResult resultString = new StreamResult(writer); File output = new File(documentFileName); StreamResult resultFile = new StreamResult(output); DOMSource source = new DOMSource(node); try {// ww w. j av a2 s. c o m Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.INDENT, "yes"); t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); t.setOutputProperty(OutputKeys.METHOD, "xml"); t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); t.transform(source, resultFile); // t.transform(source, resultString); } catch (TransformerException e) { e.printStackTrace(); } // return writer.toString(); } }