Here you can find the source of document2String(Document doc)
public static String document2String(Document doc) throws ParserConfigurationException, TransformerConfigurationException, TransformerException
//package com.java2s; //License from project: LGPL import java.io.StringWriter; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; 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.Document; public class Main { public static String document2String(Document doc) throws ParserConfigurationException, TransformerConfigurationException, TransformerException { DocumentBuilderFactory domFact = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = domFact.newDocumentBuilder(); DOMSource domSource = new DOMSource(doc); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.transform(domSource, result); return writer.toString(); }/* ww w .ja va 2 s . co m*/ }