Here you can find the source of toXMLString(Node node)
public static String toXMLString(Node node)
//package com.java2s; /*/* w w w . j a va 2s . co m*/ * JFox - The most lightweight Java EE Application Server! * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn. * * JFox is licenced and re-distributable under GNU LGPL. */ import java.io.StringWriter; import javax.xml.transform.OutputKeys; 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.Node; 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 ""; } } }