Here you can find the source of printToTerminal(Node n, String indent, boolean descend)
public static void printToTerminal(Node n, String indent, boolean descend)
//package com.java2s; //License from project: Open Source License import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static void printToTerminal(Node n, String indent, boolean descend) { if (n != null) { System.out.println(indent + "Name: " + n.getNodeName()); System.out.println(indent + "NS : " + n.getNamespaceURI()); System.out.println(indent + "txt : " + n.getTextContent()); System.out.println(indent + "Type: " + n.getNodeType()); System.out.println(indent + "Val : [" + n.getNodeValue() + "]"); if (n.hasAttributes()) printAttributesCompact(n.getAttributes(), indent, descend); if (descend && n.hasChildNodes()) printChildNode(n.getChildNodes(), indent, descend); if (indent == "") System.out.println(indent + "________________________\n"); }//w w w . j a v a2s . c om } private static void printAttributesCompact(NamedNodeMap attributes, String indent, boolean descend) { System.out.println(indent + "Attributes: " + getAttributesCompact(attributes)); } private static void printChildNode(NodeList childNodes, String indent, boolean descend) { System.out.println(); for (int i = 0; i < childNodes.getLength(); ++i) { System.out.println(indent + "-- Child: " + i + " ---------"); printToTerminal(childNodes.item(i), indent + " ", descend); } System.out.println(indent + "-- ^last child ------\n"); } private static String getAttributesCompact(NamedNodeMap attributes) { String s = "["; for (int i = 0; i < attributes.getLength(); ++i) { Node n = attributes.item(i); s += n.getNodeName() + "=\"" + n.getNodeValue() + "\""; s += ", "; } s += "]"; return s; } }