Here you can find the source of serializeXMLToFile(Document document, File output)
public static void serializeXMLToFile(Document document, File output)
//package com.java2s; import java.io.File; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; 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 { /**/*from ww w .j a v a 2s. co m*/ * Serializes an XML document to disk * */ public static void serializeXMLToFile(Document document, File output) { try { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource domSource = new DOMSource(document); StreamResult result = new StreamResult(output); transformer.transform(domSource, result); } catch (TransformerConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TransformerException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }