Here you can find the source of serializeNode(Node node)
public static String serializeNode(Node node) throws LSException, IllegalAccessException, DOMException, InstantiationException, ClassNotFoundException, ClassCastException
//package com.java2s; import org.w3c.dom.DOMException; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.ls.DOMImplementationLS; import org.w3c.dom.ls.LSException; import org.w3c.dom.ls.LSSerializer; public class Main { public static String serializeNode(Node node) throws LSException, IllegalAccessException, DOMException, InstantiationException, ClassNotFoundException, ClassCastException { String serializedElement = null; if (node != null) { DOMImplementationLS impl = getDOMImplementationLS(node); LSSerializer writer = impl.createLSSerializer(); serializedElement = writer.writeToString(node); }/* www . j a v a 2s .co m*/ return serializedElement; } protected static DOMImplementationLS getDOMImplementationLS(Node node) { Document document = node.getOwnerDocument(); return (DOMImplementationLS) document.getImplementation(); } }