Java tutorial
//package com.java2s; //License from project: Apache License import java.io.StringWriter; 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 { /** * Creates a {@link String} out of a {@link Node} * * @param node * never <code>null</code> * @return the node as string, never <code>null</code> * @throws Exception */ public static String asString(Node node) throws Exception { StringWriter writer = new StringWriter(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(new DOMSource(node), new StreamResult(writer)); return writer.toString(); } }