Java XML Node Print printNodeBasics(Node node)

Here you can find the source of printNodeBasics(Node node)

Description

Prints a given Node

For debugging purpose only

License

Apache License

Declaration


public static void printNodeBasics(Node node)

    

Method Source Code

//package com.java2s;
/*//from   ww w .j  a  va  2s  .c o  m
 * Copyright 2015 www.seleniumtests.com
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import org.w3c.dom.Node;

public class Main {
    /**
     * Prints a given Node<br>
     * <p/>
     * For debugging purpose only
     */

    public static void printNodeBasics(Node node)

    {

        if (node == null)

        {

            System.out.println(" Null node");

            return;

        }

        System.out.println(" Node[Namespace URI=" + node.getNamespaceURI() + " localname=" +

                node.getLocalName() + " name=" +

                node.getNodeName() + " type=" +

                getNodeTypeStr(node.getNodeType()) + " Value=" + node.getNodeValue() +

                "]");

    }

    /**
     * Gets Node type String for a given node type constant
     */

    public static String getNodeTypeStr(int nodeType)

    {

        switch (nodeType)

        {

        case Node.ATTRIBUTE_NODE:

            return "ATTRIBUTE_NODE ";

        case Node.CDATA_SECTION_NODE:

            return "CDATA_SECTION_NODE";

        case Node.COMMENT_NODE:

            return "COMMENT_NODE";

        case Node.DOCUMENT_FRAGMENT_NODE:

            return "DOCUMENT_FRAGMENT_NODE";

        case Node.DOCUMENT_TYPE_NODE:

            return "DOCUMENT_TYPE_NODE";

        case Node.ELEMENT_NODE:

            return "ELEMENT_NODE";

        case Node.ENTITY_NODE:

            return "ENTITY_NODE";

        case Node.ENTITY_REFERENCE_NODE:

            return "ENTITY_REFERENCE_NODE";

        case Node.NOTATION_NODE:

            return "NOTATION_NODE";

        case Node.PROCESSING_INSTRUCTION_NODE:

            return "PROCESSING_INSTRUCTION_NODE";

        case Node.TEXT_NODE:

            return "TEXT_NODE";

        case Node.DOCUMENT_NODE:

            return "DOCUMENT_NODE";

        default:

            return "UN-INDENTIFIED NODE";

        }

    }
}

Related

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