Here you can find the source of xmlToString(Node node)
public static String xmlToString(Node node) throws TransformerException
//package com.java2s; /** Escaping code for XML borrowed from org.json.XML * Full license and code available https://github.com/douglascrockford/JSON-java/blob/master/XML.java * @param string The string to be encoded * @return An encoded copy of the string **//* w w w .j ava 2 s . c o m*/ import java.io.StringWriter; 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.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Node; public class Main { public static String xmlToString(Node node) throws TransformerException { Source source = new DOMSource(node); StringWriter stringWriter = new StringWriter(); Result result = new StreamResult(stringWriter); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.transform(source, result); return stringWriter.getBuffer().toString(); } }