Here you can find the source of doc2XmlFile(Document doc, String filename)
public static boolean doc2XmlFile(Document doc, String filename)
//package com.java2s; import java.io.File; 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 boolean doc2XmlFile(Document doc, String filename) { boolean flag = true; try {// www . j a v a2 s . c om TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(new File(filename)); transformer.transform(source, result); } catch (Exception ex) { flag = false; ex.printStackTrace(); } return flag; } }