Here you can find the source of storeXml(final File xmlFile, final Document document)
public static void storeXml(final File xmlFile, final Document document) throws TransformerException
//package com.java2s; //License from project: Open Source 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.Document; public class Main { public static void storeXml(final File xmlFile, final Document document) throws TransformerException { if (xmlFile == null) { throw new NullPointerException("xmlFile"); }/* www.j a v a 2 s. c om*/ if (xmlFile.exists() && !xmlFile.canWrite()) { throw new IllegalArgumentException("xmlFile"); } if (xmlFile.exists() && !xmlFile.isFile()) { throw new IllegalArgumentException("xmlFile"); } if (document == null) { throw new NullPointerException("document"); } StreamResult result = new StreamResult(xmlFile); DOMSource source = new DOMSource(document); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.transform(source, result); } }