Java XML Attribute Get getAttributeValue(Element el, String attrName)

Here you can find the source of getAttributeValue(Element el, String attrName)

Description

Get the value from the given attribute

License

Apache License

Return

null if the attribute value is empty or the attribute is not present

Declaration

public static String getAttributeValue(Element el, String attrName) 

Method Source Code

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

import javax.xml.namespace.QName;

import org.w3c.dom.Element;

public class Main {
    /** //ww w. java 2 s .  c  o  m
     * Get the value from the given attribute
     * @return null if the attribute value is empty or the attribute is not present
     */
    public static String getAttributeValue(Element el, String attrName) {
        return getAttributeValue(el, new QName(attrName));
    }

    /** 
     * Get the value from the given attribute
     * @return null if the attribute value is empty or the attribute is not present
     */
    public static String getAttributeValue(Element el, QName attrName) {
        String attr = null;
        if ("".equals(attrName.getNamespaceURI()))
            attr = el.getAttribute(attrName.getLocalPart());
        else
            attr = el.getAttributeNS(attrName.getNamespaceURI(), attrName.getLocalPart());

        if ("".equals(attr))
            attr = null;

        return attr;
    }
}

Related

  1. getAttributeValue(@Nonnull final Element aElement, @Nonnull final String sAttrName)
  2. getAttributeValue(Element e, String key)
  3. getAttributeValue(Element e, String name)
  4. getAttributeValue(Element el, String attributeName)
  5. getAttributeValue(Element el, String attributeName)
  6. getAttributeValue(Element ele, String attrName)
  7. getAttributeValue(Element elem, String name)
  8. getAttributeValue(Element element, String attr)
  9. getAttributeValue(Element element, String attributeName)