Here you can find the source of getNodeXml(Node node)
public static String getNodeXml(Node node) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.StringWriter; import javax.xml.transform.OutputKeys; 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 getNodeXml(Node node) throws Exception { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer trans = transformerFactory.newTransformer(); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); StringWriter sw = new StringWriter(); trans.transform(new DOMSource(node), new StreamResult(sw)); return sw.getBuffer().toString(); }//from w ww . j av a 2 s. co m }