Java tutorial
//package com.java2s; // modify it under the terms of the GNU General Public License import java.io.StringWriter; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import org.w3c.dom.Node; public class Main { public static String getAsText(Node n) { try { Transformer t = TransformerFactory.newInstance().newTransformer(); StringWriter out = new StringWriter(); t.transform(new javax.xml.transform.dom.DOMSource(n), new javax.xml.transform.stream.StreamResult(out)); return out.toString(); } catch (Throwable t) { t.printStackTrace(); return null; } } }