Java tutorial
//package com.java2s; import java.io.File; 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 { /** * Stores an XMl document into a file. * * @param doc xml document to be stored * @param location absolute path where to write down the document * @throws TransformerException If an unrecoverable error occurs during the * course of the transformation. */ public static void save(Document doc, String location) throws TransformerException { doc.normalize(); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult streamResult = new StreamResult(new File(location)); transformer.transform(source, streamResult); } }