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 { private static TransformerFactory transformerFactory = TransformerFactory.newInstance(); public static String node2String(Node node) throws Exception { if (node == null) return null; StringWriter out = null; try { Transformer transformer = transformerFactory.newTransformer(); out = new StringWriter(); transformer.transform(new DOMSource(node), new StreamResult(out)); return out.toString(); } catch (Exception e) { throw e; } finally { if (out != null) out.close(); } } }