Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * 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 {
    /**
     * Gets Nodes basic information such as Node name, type, value, namespace
     * <p/>
     * and local name
     */

    public static String getNodeBasics(Node node)

    {

        StringBuffer sb = new StringBuffer();

        if (node == null)

        {

            sb.append(" Null node");

            return sb.toString();

        }

        sb.append(" Node[Namespace URI=" + node.getNamespaceURI() + " localname=" +

                node.getLocalName() + " name=" +

                node.getNodeName() + " type=" +

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

                "]");

        return sb.toString();

    }

    /**
     * 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";

        }

    }
}