Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.w3c.dom.Node;

public class Main {
    /***
     * Get the name of the node without namespace
     * 
     * @param node
     * @return
     */
    public static String getNodeName(final Node node) {

        if (node == null) {
            return null;
        }

        String nodeName = node.getNodeName();

        // Remove namespace prefix if present
        int indexOfColon;
        if ((nodeName != null) && (nodeName.length() > 0 // Node name is not
        // empty
        ) && ((indexOfColon = nodeName.indexOf(':')) >= 0)
        // there is a colon in the nodename
                && (indexOfColon < (nodeName.length() - 1))
        // colon is not at the end of the name
        ) {
            nodeName = nodeName.substring(nodeName.indexOf(':') + 1);
        }

        return nodeName;
    }
}