Here you can find the source of nodeToString(final Node node)
public static String nodeToString(final Node node)
//package com.java2s; //License from project: Open Source License import java.io.StringWriter; import javax.xml.transform.OutputKeys; 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 nodeToString(final Node node) { final TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer transformer;// w ww . j ava2 s .c o m try { transformer = transFactory.newTransformer(); final StringWriter buffer = new StringWriter(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.transform(new DOMSource(node), new StreamResult(buffer)); buffer.append("\n"); return buffer.toString(); } catch (final Exception e) { throw new RuntimeException(e); } } }