Java XML Attribute from Element getValueAttribute(final Node aNode)

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

Description

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

License

Apache License

Parameter

Parameter Description
aNode A DOM Node.

Return

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

Declaration

public static String getValueAttribute(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 VALUE_ATTRIBUTE = "value";

    /**//ww  w.j  a  va  2  s.com
     * Retrieves the value of the {@code value} attribute of the supplied Node.
     *
     * @param aNode A DOM Node.
     * @return the value of the {@code value} attribute of the supplied Node/Element.
     */
    public static String getValueAttribute(final Node aNode) {
        return getNamedAttribute(aNode, VALUE_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. getTagAttributeRecursive(String sTag, String sAtt, Element eElement)
  2. getTagAttributes(Element element)
  3. getThisClassTypeAttr(Element methodNode)
  4. getTrimedAttribute(Element elem, String attr_name)
  5. getValue(final Element elem, final String attrName)
  6. getValueAttributeUri(Element parent, String defaultBaseUri)
  7. getValueForAttribute(String attributeName, Node parentNode)
  8. getXMLAttribute(Element element, String attrName)
  9. getXMLAttributeValue(Element node, String attributeName)