Java XML Node Get by Name getElementTagName(final Node aNode)

Here you can find the source of getElementTagName(final Node aNode)

Description

Retrieves the TagName for the supplied Node if it is an Element, and null otherwise.

License

Apache License

Parameter

Parameter Description
aNode A DOM Node.

Return

The TagName of the Node if it is an Element, and null otherwise.

Declaration

public static String getElementTagName(final Node aNode) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.Element;

import org.w3c.dom.Node;

public class Main {
    /**/* w  w  w .jav  a2  s .c o m*/
     * Retrieves the TagName for the supplied Node if it is an Element, and null otherwise.
     *
     * @param aNode A DOM Node.
     * @return The TagName of the Node if it is an Element, and null otherwise.
     */
    public static String getElementTagName(final Node aNode) {

        if (aNode != null && aNode.getNodeType() == Node.ELEMENT_NODE) {

            final Element theElement = (Element) aNode;
            return theElement.getTagName();
        }

        // The Node was not an Element.
        return null;
    }
}

Related

  1. getElementsByTagName(Node node, String tagname)
  2. getElementsByTagName(Node node, String tagName)
  3. getElementsByTagName(Node root, String tagName)
  4. getElementsByTagNameNS(Node element, String namespace, String name)
  5. getElementsByTagNames(Node node, String... tagName)