Java XML Attribute Get getAttributeValueAsLong(final Element el, final String attrName, final long defaultVal)

Here you can find the source of getAttributeValueAsLong(final Element el, final String attrName, final long defaultVal)

Description

get Attribute Value As Long

License

Apache License

Declaration

public static long getAttributeValueAsLong(final Element el, final String attrName, final long defaultVal) 

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 long getAttributeValueAsLong(final Element el, final String attrName, final long defaultVal) {
        return getAttributeValueAsLong(el, new QName(attrName), defaultVal);
    }/*from  ww  w. j a  va  2 s  .c om*/

    public static long getAttributeValueAsLong(final Element el, final QName attrName, final long defaultVal) {
        final String attrVal = getAttributeValue(el, attrName);
        return attrVal != null ? new Long(attrVal) : defaultVal;
    }

    public static String getAttributeValue(final Element el, final String attrName) {
        return getAttributeValue(el, new QName(attrName));
    }

    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(String attributeName, Node xmlNode)
  2. getAttributeValueAsBoolean(Attr attribute)
  3. getAttributeValueAsBoolean(Element el, String attrName)
  4. getAttributeValueAsDouble(Node node, String attributeName)
  5. getAttributeValueAsInteger(Node node, String attributeName, Integer defaultValue)
  6. getAttributeValueAsString(Node node)
  7. getAttributeValueBoolean(Node node, String attrName)
  8. getAttributeValueByName(NamedNodeMap nnm, String name)
  9. getAttributeValueByName(NamedNodeMap nnm, String name)