Here you can find the source of convert(final Element element)
public static String convert(final Element element) throws NullPointerException, TransformerException
//package com.java2s; // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell import java.io.StringWriter; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Element; public class Main { public static String convert(final Element element) throws NullPointerException, TransformerException { if (null == element) { throw new NullPointerException("connot convert null DOM Element"); }//from ww w .jav a2 s .co m TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer transformer = transFactory.newTransformer(); StringWriter stringWriter = new StringWriter(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.transform(new DOMSource(element), new StreamResult(stringWriter)); return stringWriter.toString(); } }