Here you can find the source of getDescriptionOfNode(Node node)
public static String getDescriptionOfNode(Node node)
//package com.java2s; //License from project: Open Source License import java.io.*; import javax.xml.transform.*; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.*; public class Main { public static String getDescriptionOfNode(Node node) { if (!(node instanceof Element)) { return domToString(node); }//from w ww.ja v a2s .co m final String id = ((Element) node).getAttribute("id"); if ((id == null) || (id.length() == 0)) { return domToString(node); } return "Node: id=" + id; } static String domToString(Node node) { try { TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(node), new StreamResult(writer)); return writer.toString(); } catch (TransformerException te) { return "(TransformerException)"; } } }