Here you can find the source of elementToString(Element element)
public static String elementToString(Element element)
//package com.java2s; //License from project: Open Source License 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 element) { DOMImplementationLS lsImpl = (DOMImplementationLS) element.getOwnerDocument().getImplementation() .getFeature("LS", "3.0"); LSSerializer serializer = lsImpl.createLSSerializer(); serializer.getDomConfig().setParameter("xml-declaration", false); //by default its true, so set it to false to get String without xml-declaration return serializer.writeToString(element); }/* www. j av a 2 s . co m*/ }