Java XML Attribute Read getNameAttribute(final Node aNode)

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

Description

Retrieves the value of the name attribute of the supplied Node.

License

Apache License

Parameter

Parameter Description
aNode A DOM Node.

Return

the value of the name attribute of the supplied Node/Element.

Declaration

public static String getNameAttribute(final Node aNode) 

Method Source Code

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

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class Main {
    private static final String NAME_ATTRIBUTE = "name";

    /**//from  w  ww . j  a  v  a  2 s.co m
     * Retrieves the value of the {@code name} attribute of the supplied Node.
     *
     * @param aNode A DOM Node.
     * @return the value of the {@code name} attribute of the supplied Node/Element.
     */
    public static String getNameAttribute(final Node aNode) {
        return getNamedAttribute(aNode, NAME_ATTRIBUTE);
    }

    private static String getNamedAttribute(final Node aNode, final String attributeName) {

        // Fail fast
        if (aNode == null) {
            return null;
        }

        final NamedNodeMap attributes = aNode.getAttributes();
        if (attributes != null) {

            final Node nameNode = attributes.getNamedItem(attributeName);
            if (nameNode != null) {
                return nameNode.getNodeValue().trim();
            }
        }

        // Not found.
        return null;
    }
}

Related

  1. getLong(Node xmlNode, String attributeLabel)
  2. getLong(String attrName, Map runtimeAttributes, Node docElement)
  3. getLongAttribute(NamedNodeMap namedNodeMap, String name)
  4. getLongAttribute(String name, Element el)
  5. getNamedAttribute(final Node aNode, final String attributeName)
  6. getNewAttribute(Element element, String name)
  7. getNSPrefixFromNSAttr(Attr a)
  8. getNullableAttribute(final Element node, final String attributeName)