Here you can find the source of toString(Node node, StringBuilder sb)
public static void toString(Node node, StringBuilder sb)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { public static String toString(Node node) { StringBuilder sb = new StringBuilder(); toString(node, sb);/*from w ww . ja v a 2 s . c om*/ return sb.toString(); } public static void toString(Node node, StringBuilder sb) { sb.append(node.getClass().getSimpleName()); if (node instanceof Element) { Element el = (Element) node; sb.append(":"); sb.append(el.getNodeName()); sb.append(" "); attrToString(el, sb); } } public static void attrToString(Element el, StringBuilder sb) { if (el.hasAttributes() == false) { return; } NamedNodeMap attrs = el.getAttributes(); for (int i = 0; i < attrs.getLength(); ++i) { sb.append(" "); Node att = attrs.item(i); sb.append(att); } } }