Here you can find the source of toText(Node node)
public static String toText(Node node)
//package com.java2s; //License from project: BSD License import java.io.ByteArrayOutputStream; import javax.xml.transform.OutputKeys; import javax.xml.transform.Result; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Node; public class Main { public static String toText(Node node) { try {// w ww . ja v a2s . c o m DOMSource source = new DOMSource(node); Transformer identity = TransformerFactory.newInstance().newTransformer(); identity.setOutputProperty(OutputKeys.INDENT, "no"); identity.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); // identity.setOutputProperty(OutputKeys.METHOD, "text"); // identity.setOutputProperty(OutputKeys.METHOD, "xml"); // identity.setOutputProperty(OutputKeys.METHOD, "html"); // class // com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl ByteArrayOutputStream baos = new ByteArrayOutputStream(); Result result = new StreamResult(baos); identity.transform(source, result); return new String(baos.toString("UTF-8")); } catch (Exception e) { throw new RuntimeException(e); } } }