Here you can find the source of writeXmlFile(Document doc, String filename)
public static void writeXmlFile(Document doc, String filename) throws TransformerException
//package com.java2s; import org.w3c.dom.Document; import javax.xml.transform.*; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import java.io.File; public class Main { public static void writeXmlFile(Document doc, String filename) throws TransformerException { // Prepare the DOM document for writing Source source = new DOMSource(doc); // Prepare the output file File file = new File(filename); Result result = new StreamResult(file); // Write the DOM document to the file Transformer xformer = TransformerFactory.newInstance() .newTransformer();/*w w w . ja v a 2 s . c o m*/ xformer.transform(source, result); } }