Here you can find the source of elementToString(Element el)
public static String elementToString(Element el)
//package com.java2s; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.ls.DOMImplementationLS; import org.w3c.dom.ls.LSSerializer; public class Main { public static String elementToString(Element el) { if (el == null) return ""; Document document = el.getOwnerDocument(); DOMImplementationLS domImplLS = (DOMImplementationLS) document .getImplementation();//from www. ja va 2s . co m LSSerializer serializer = domImplLS.createLSSerializer(); return serializer.writeToString(el); } }