Java tutorial
//package com.java2s; //License from project: Apache License import org.w3c.dom.*; 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 java.io.StringWriter; public class Main { public static String convertDocumentToString(Document dom) { TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer; try { transformer = tf.newTransformer(); StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(dom), new StreamResult(writer)); String output = writer.getBuffer().toString(); return output; } catch (TransformerException e) { e.printStackTrace(); } return null; } }