Java XML Attribute from Element getValue(final Element elem, final String attrName)

Here you can find the source of getValue(final Element elem, final String attrName)

Description

Get attribute value.

License

Apache License

Parameter

Parameter Description
elem attribute parent element
attrName attribute name

Return

attribute value, null if not set

Declaration

public static String getValue(final Element elem, final String attrName) 

Method Source Code

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

import org.w3c.dom.*;

public class Main {
    /**/*from w  w w .  j av a 2  s. c  o  m*/
     * Get attribute value.
     *
     * @param elem attribute parent element
     * @param attrName attribute name
     * @return attribute value, {@code null} if not set
     */
    public static String getValue(final Element elem, final String attrName) {
        final Attr attr = elem.getAttributeNode(attrName);
        if (attr != null && !attr.getValue().isEmpty()) {
            return attr.getValue();
        }
        return null;
    }
}

Related

  1. getTagAttribute(XMLStreamReader xmler, String attribute, String defaultValue)
  2. getTagAttributeRecursive(String sTag, String sAtt, Element eElement)
  3. getTagAttributes(Element element)
  4. getThisClassTypeAttr(Element methodNode)
  5. getTrimedAttribute(Element elem, String attr_name)
  6. getValueAttribute(final Node aNode)
  7. getValueAttributeUri(Element parent, String defaultBaseUri)
  8. getValueForAttribute(String attributeName, Node parentNode)
  9. getXMLAttribute(Element element, String attrName)