Java tutorial
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.OutputStream; import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.TransformerFactoryConfigurationError; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Node; public class Main { public static String toString(Node node) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { toText(node, baos); } catch (Exception e) { //logger.error(ExceptionUtil.toString(e)); throw new RuntimeException(e); //return null; } return baos.toString(); } public static void toText(Node node, OutputStream out) throws TransformerFactoryConfigurationError, TransformerException { Transformer transformer = TransformerFactory.newInstance().newTransformer(); Source source = new DOMSource(node); Result output = new StreamResult(out); transformer.transform(source, output); } }