Java tutorial
//package com.java2s; 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.Document; public class Main { public static String getDOMString(Document doc) { String s = null; final TransformerFactory tfactory = TransformerFactory.newInstance(); try { final Transformer xform = tfactory.newTransformer(); final Source src = new DOMSource(doc); final StringWriter writer = new StringWriter(); final Result result = new StreamResult(writer); xform.transform(src, result); s = writer.toString(); } catch (final Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return s; } }