Here you can find the source of printAttributes(NamedNodeMap attributes, String indent, boolean descend)
@SuppressWarnings("unused") private static void printAttributes(NamedNodeMap attributes, 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 { @SuppressWarnings("unused") private static void printAttributes(NamedNodeMap attributes, String indent, boolean descend) { System.out.println();/*from w ww. j ava 2 s.c o m*/ for (int i = 0; i < attributes.getLength(); ++i) { System.out.println(indent + "-- Attribute: " + i + " -----"); printToTerminal(attributes.item(i), indent + " ", descend); } System.out.println(indent + "-- ^last attribute --\n"); } 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"); } } 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; } }