Here you can find the source of printNodeType(Node node, int ident)
Parameter | Description |
---|---|
node | node to print type of |
ident | amount to indent |
public static void printNodeType(Node node, int ident)
//package com.java2s; import org.w3c.dom.*; public class Main { /**prints the type of the input node * @param node node to print type of/*from w w w .j av a 2 s. c o m*/ * @param ident amount to indent*/ public static void printNodeType(Node node, int ident) { System.out.print("Node: " + node.getNodeName() + " "); switch (node.getNodeType()) { case Node.DOCUMENT_NODE: System.out.println("Document Node"); break; case Node.ELEMENT_NODE: System.out.println("Element Node"); for (int j = 0; j < 2 * ident; j++) System.out.print(" "); System.out.println("It has the following Children"); NodeList children = node.getChildNodes(); if (children != null) { for (int i = 0; i < children.getLength(); i++) { for (int j = 0; j < ident; j++) System.out.print(" "); System.out.print("Child " + ident + "." + i + " = "); printNodeType(children.item(i), ident + 1); } System.out.println(); } break; case Node.TEXT_NODE: System.out.println("->" + node.getNodeValue().trim() + "<-"); break; case Node.CDATA_SECTION_NODE: System.out.println("CData Node"); break; case Node.PROCESSING_INSTRUCTION_NODE: System.out.println("Proposing Instruction Node"); break; case Node.ENTITY_REFERENCE_NODE: System.out.println("Entity Node"); break; case Node.DOCUMENT_TYPE_NODE: System.out.println("Document Node"); break; default: } } }