Java XML Node Print printNodeType(Node node, int ident)

Here you can find the source of printNodeType(Node node, int ident)

Description

prints the type of the input node

License

Open Source License

Parameter

Parameter Description
node node to print type of
ident amount to indent

Declaration

public static void printNodeType(Node node, int ident) 

Method Source Code


//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:
        }
    }
}

Related

  1. printNode(Node node, PrintStream out)
  2. printNode(Node node, StringWriter sw)
  3. printNodeBasics(Node node)
  4. printNodeIterator(NodeIterator iterator)
  5. printNodes(Node node, int level)
  6. printToTerminal(Node n, String indent, boolean descend)
  7. printTree(Node node, int ident)
  8. printTree(Node root, int level)