Here you can find the source of xmlToString(Document doc)
public static String xmlToString(Document doc)
//package com.java2s; 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.Document; public class Main { public static String xmlToString(Document doc) { final StringWriter sw = new StringWriter(); TransformerFactory transformerFactory = TransformerFactory .newInstance();// w ww.ja va 2 s.c om try { Transformer transformer = transformerFactory.newTransformer(); transformer.transform(new DOMSource(doc), new StreamResult(sw)); return sw.toString(); } catch (Exception e) { throw new RuntimeException(e); } } }