Here you can find the source of writeXmlFile(File file, Document document)
public final static synchronized long writeXmlFile(File file, Document document) throws Exception
//package com.java2s; //License from project: Apache License import java.io.File; import java.util.Properties; 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 final static synchronized long writeXmlFile(File file, Document document) throws Exception { DOMSource doms = new DOMSource(document); StreamResult result = new StreamResult(file); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); Properties properties = transformer.getOutputProperties(); properties.setProperty(OutputKeys.ENCODING, "utf-8"); properties.setProperty(OutputKeys.METHOD, "xml"); properties.setProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperties(properties); transformer.transform(doms, result); return 0; }/* w w w. jav a 2s . co m*/ }