Here you can find the source of toString(Element e)
public static String toString(Element e)
//package com.java2s; //License from project: Apache License import org.w3c.dom.Element; import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import java.io.StringWriter; public class Main { public static String toString(Element e) { try {// w w w .j a v a2s .c om TransformerFactory tfactory = TransformerFactory.newInstance(); Transformer xform = tfactory.newTransformer(); Source src = new DOMSource(e); java.io.StringWriter writer = new StringWriter(); Result result = new javax.xml.transform.stream.StreamResult(writer); xform.transform(src, result); return writer.toString(); } catch (Exception ex) { return "Unable to convert to string: " + ex.toString(); } } }