Here you can find the source of getAsText(Node n)
public static String getAsText(Node n)
//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 {//from w w w .ja v a 2 s . c o m 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; } } }