Here you can find the source of SaveDom(Document dom, String filepath)
public static void SaveDom(Document dom, String filepath)
//package com.java2s; // under the terms of the GNU General Public License as published by the import org.w3c.dom.*; import java.io.*; import javax.xml.transform.*; import javax.xml.transform.dom.*; import javax.xml.transform.stream.*; public class Main { public static void SaveDom(Document dom, String filepath) { try {//from ww w. j av a 2 s . co m TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource domSource = new DOMSource(dom); StreamResult streamResult = new StreamResult(new FileOutputStream(filepath)); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8"); transformer.transform(domSource, streamResult); } catch (Exception e) { throw new RuntimeException(e); } } }