Java tutorial
//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.Node; public class Main { public static String printNode(Node node) { String result = ""; try { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty("method", "xml"); StringWriter sw = new StringWriter(); DOMSource source = new DOMSource(node); transformer.transform(source, new StreamResult(sw)); result = sw.toString(); } catch (Exception e) { e.printStackTrace(); } return result; } }