Here you can find the source of serialize(Document document, File targetFile)
public static void serialize(Document document, File targetFile) throws IOException
//package com.java2s; //License from project: Apache License import org.w3c.dom.Document; 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 java.io.File; import java.io.IOException; public class Main { public static void serialize(Document document, File targetFile) throws IOException { try {//from w w w.ja v a 2 s. c o m Transformer t = TransformerFactory.newInstance().newTransformer(); t.transform(new DOMSource(document), new StreamResult(targetFile)); } catch (TransformerException e) { throw new IOException(e); } } }