Here you can find the source of transfer(Document doc, String filepath)
public static void transfer(Document doc, String filepath)
//package com.java2s; //License from project: Apache License 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 { private static TransformerFactory tff; public static void transfer(Document doc, String filepath) { try {//from ww w . ja v a 2 s. c o m Transformer tf = tff.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(filepath); tf.transform(source, result); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } } }