Here you can find the source of getOuterXml(Node n)
public static String getOuterXml(Node n)
//package com.java2s; //License from project: LGPL import java.io.StringWriter; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; 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 getOuterXml(Node n) { //For debug only... TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer transformer = null; try {//from w w w . ja v a 2 s .c o m transformer = transFactory.newTransformer(); } catch (TransformerConfigurationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); return ""; } try { StringWriter buffer = new StringWriter(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.transform(new DOMSource(n), new StreamResult(buffer)); return buffer.toString(); } catch (TransformerConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); return ""; } catch (TransformerException e) { // TODO Auto-generated catch block e.printStackTrace(); return ""; } } }