Here you can find the source of write2Xml(Document document)
public static void write2Xml(Document document) throws Exception
//package com.java2s; //License from project: Apache License import java.io.FileOutputStream; 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 { private static String fileName = "src/main/resources/xml/exam.xml"; public static void write2Xml(Document document) throws Exception { TransformerFactory factory = TransformerFactory.newInstance(); Transformer tf = factory.newTransformer(); tf.transform(new DOMSource(document), new StreamResult(new FileOutputStream(fileName))); }/* ww w . j a v a 2s. c o m*/ }