Here you can find the source of nodeToString(Node node)
public static String nodeToString(Node node) throws TransformerException
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Node; import javax.xml.transform.*; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import java.io.StringWriter; public class Main { public static String nodeToString(Node node) throws TransformerException { Source source = new DOMSource(node); StringWriter stringWriter = new StringWriter(); Result result = new StreamResult(stringWriter); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.transform(source, result); return stringWriter.getBuffer().toString(); }/*from w w w . jav a2s. c o m*/ }