Here you can find the source of write2xml(Document document)
public static void write2xml(Document document)
//package com.java2s; //License from project: Apache License import org.w3c.dom.Document; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; public class Main { public static void write2xml(Document document) { try {/*from w w w . j a va2s .c om*/ Transformer ts = TransformerFactory.newInstance().newTransformer(); ts.transform(new DOMSource(document), new StreamResult("xml/exam.xml")); } catch (Exception e) { e.printStackTrace(); } } }