Here you can find the source of save(final String path, final Document xml)
public static void save(final String path, final Document xml) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.FileOutputStream; 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 static void save(final String path, final Document xml) throws Exception { try {//from w w w . ja v a 2s . c o m final Transformer tr = TransformerFactory.newInstance().newTransformer(); tr.setOutputProperty(OutputKeys.INDENT, "yes"); tr.setOutputProperty(OutputKeys.METHOD, "xml"); tr.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); // tr.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "roles.dtd"); tr.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); // send DOM to file tr.transform(new DOMSource(xml), new StreamResult(new FileOutputStream(path))); } catch (final Exception e) { e.printStackTrace(); throw new Exception("XMLUtil - save: error"); } } }