Here you can find the source of serialize(Document d, File f)
public static void serialize(Document d, File f)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileOutputStream; import java.io.IOException; 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 TransformerFactory tf; public static void serialize(Document d, File f) { try {//from w w w .ja va2 s .co m doSerialize(d, f); } catch (TransformerException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public static void doSerialize(Document d, File f) throws TransformerException, IOException { Transformer t = tf.newTransformer(); FileOutputStream fos = new FileOutputStream(f); StreamResult sr = new StreamResult(fos); t.transform(new DOMSource(d), sr); fos.close(); } }