Java tutorial
//package com.java2s; import org.w3c.dom.*; import javax.xml.transform.*; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import java.io.*; public class Main { private final static TransformerFactory tf = TransformerFactory.newInstance(); public static String toXMLString(Node node) { if (node == null) { return ""; } try { Transformer tran = tf.newTransformer(); tran.setOutputProperty(OutputKeys.INDENT, "yes"); StringWriter swriter = new StringWriter(); Source src = new DOMSource(node); Result res = new StreamResult(swriter); tran.transform(src, res); return swriter.getBuffer().toString(); } catch (Exception e) { e.printStackTrace(); return ""; } } }