Java XML Attribute Get getAttributeAsLong(Element element, String attrName, Long defValue)

Here you can find the source of getAttributeAsLong(Element element, String attrName, Long defValue)

Description

Get the value of the given attribute of this Element as a java.lang.Long value.

License

Open Source License

Parameter

Parameter Description
element Element
attrName name of the attribute to parse
defValue Default Long value if a valid Long text not found.

Return

Returns the value of the attribute parsed as Long. Returns defValue if the given attribute is not found, or its value is not a valid Long.

Declaration

public static final Long getAttributeAsLong(Element element, String attrName, Long defValue) 

Method Source Code

//package com.java2s;

import org.w3c.dom.Element;

public class Main {
    /**//from w  w  w . j  av  a 2  s . c  o  m
     * Get the value of the given attribute of this Element as a java.lang.Long value.
     * 
     * @param element
     *            Element
     * @param attrName
     *            name of the attribute to parse
     * @param defValue
     *            Default Long value if a valid Long text not found.
     * 
     * @return Returns the value of the attribute parsed as Long. Returns defValue if the given attribute is not found,
     *         or its value is not a valid Long.
     */
    public static final Long getAttributeAsLong(Element element, String attrName, Long defValue) {
        try {
            return Long.valueOf(element.getAttribute(attrName));
        } catch (Exception ex) {
        }

        return defValue;
    }
}

Related

  1. getAttributeAsBoolean(Element element, String attrName, boolean defValue)
  2. getAttributeAsBoolean(Element element, String attrName, boolean defValue)
  3. getAttributeAsBoolean(Element element, String name)
  4. getAttributeAsBoolean(NamedNodeMap map, String name)
  5. getAttributeAsInteger(Element element, String attrName, Integer defValue)
  6. getAttributeAsString(NamedNodeMap attributes, String name)
  7. getAttributeAsString(XMLStreamReader reader, String name)
  8. getAttributeAsURIString(XMLStreamReader reader, String name)
  9. getAttributeBoolean(Element aElement, String aAttributeName)