Here you can find the source of serializeDOM(Document doc)
public static String serializeDOM(Document doc)
//package com.java2s; //License from project: Apache License import java.io.StringWriter; import org.w3c.dom.Document; import org.w3c.dom.ls.DOMImplementationLS; import org.w3c.dom.ls.LSOutput; import org.w3c.dom.ls.LSSerializer; public class Main { public static String serializeDOM(Document doc) { DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation(); LSSerializer lsSerializer = domImplementation.createLSSerializer(); LSOutput output = domImplementation.createLSOutput(); output.setEncoding("UTF-8"); StringWriter stringOut = new StringWriter(); output.setCharacterStream(stringOut); lsSerializer.write(doc, output); return stringOut.toString(); }/* w w w.ja v a 2s. com*/ }