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

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

Description

get Attribute Value

License

Apache License

Declaration

public static String getAttributeValue(final Element el, final 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 {
    public static String getAttributeValue(final Element el, final String attrName) {
        return getAttributeValue(el, new QName(attrName));
    }//from  w  w w. j a v a 2s  . c  o m

    public static String getAttributeValue(final Element el, final String attrName, final String defaultVal) {
        final String retval = getAttributeValue(el, new QName(attrName));
        return retval == null ? defaultVal : retval;
    }

    public static String getAttributeValue(final Element el, final 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(Element element, String attrName)
  2. getAttributeValue(Element element, String name)
  3. getAttributeValue(Element element, String name)
  4. getAttributeValue(Element element, String tag)
  5. getAttributeValue(final Element e, final String attributeName)
  6. getAttributeValue(final Element element, final String attributeName)
  7. getAttributeValue(final Element element, final String name)
  8. getAttributeValue(final Node candidate, final String attributName)
  9. getAttributeValue(final Node iNode, final String iAttributeName)