Here you can find the source of writeDocument(Document document)
public static void writeDocument(Document document)
//package com.java2s; import org.w3c.dom.bootstrap.DOMImplementationRegistry; import org.w3c.dom.*; import org.w3c.dom.ls.DOMImplementationLS; import org.w3c.dom.ls.LSSerializer; public class Main { public static void writeDocument(Document document) { try {/*from w ww .ja v a 2 s. co m*/ DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); String documentStr = writer.writeToString(document); System.out.println("Serialized document: \n" + documentStr); } catch (Exception e) { System.out.println("ERROR writing document: \n "); e.printStackTrace(); } } }