Here you can find the source of xml(Node node)
public static String xml(Node node)
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Node; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import java.io.StringWriter; import java.io.Writer; public class Main { public static String xml(Node node) { TransformerFactory factory = TransformerFactory.newInstance(); return xml(factory, node); }//from ww w . j av a 2 s. c om public static String xml(TransformerFactory transformerFactory, Node node) { Writer writer = new StringWriter(); DOMSource source = new DOMSource(node); StreamResult result = new StreamResult(writer); try { transformerFactory.newTransformer().transform(source, result); } catch (TransformerException e) { throw new RuntimeException(e); } return writer.toString().replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", ""); } }