Java XML Node Name getNodeName(Node node)

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

Description

get Node Name

License

Open Source License

Parameter

Parameter Description
node a parameter

Return

the name of the XML node (with no name space element)

Declaration

public static String getNodeName(Node node) 

Method Source Code

//package com.java2s;
/******************************************************************************
 * Copyright (c) 2008-2013, Linagora/*from  ww  w  .  j a v  a2 s  .com*/
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *       Linagora - initial API and implementation
 *******************************************************************************/

import org.w3c.dom.Node;

public class Main {
    /**
     * @param node
     * @return the name of the XML node (with no name space element)
     */
    public static String getNodeName(Node node) {

        String name = node.getNamespaceURI() != null ? node.getLocalName() : node.getNodeName();
        if (name.contains(":")) { //$NON-NLS-1$
            String[] parts = name.split(":"); //$NON-NLS-1$
            name = parts[parts.length - 1];
        }

        return name;
    }
}

Related

  1. getNode(Node node, String nodeName)
  2. getNode(Node node, String nodeName)
  3. getNodeContent(Node item, String nodeName)
  4. getNodeContent(Node n, String nodename)
  5. getNodeName(Node node)
  6. getNodeName(Node node)
  7. getNodeName(Node node)
  8. getNodeName(Node node)
  9. getNodeNameIgnorePrefix(Node node)