Here you can find the source of toString(Node node)
public static String toString(Node node) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.StringWriter; import javax.xml.transform.Result; import javax.xml.transform.Source; 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 toString(Node node) throws Exception { StringWriter w = new StringWriter(); Source s = new DOMSource(node); Result r = new StreamResult(w); Transformer t = TransformerFactory.newInstance().newTransformer(); // t.setOutputProperty("omit-xml-declaration", "yes"); t.setOutputProperty("indent", "yes"); t.transform(s, r);/*from w w w . j av a 2 s .com*/ return w.getBuffer().toString(); } }