Here you can find the source of saveDocAsXML(Document doc, String filename)
public static void saveDocAsXML(Document doc, String filename)
//package com.java2s; //License from project: LGPL import java.io.File; import javax.xml.transform.Result; import javax.xml.transform.Source; 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 { /** export DOM document to a file -- handy for debugging **/ public static void saveDocAsXML(Document doc, String filename) { try {// w ww . ja va 2 s . c o m Transformer transformer = TransformerFactory.newInstance().newTransformer(); Result output = new StreamResult(new File(filename)); Source input = new DOMSource(doc); transformer.transform(input, output); } catch (Exception e) { e.printStackTrace(); } } }