Java XML Attribute from Element getInteger(final org.w3c.dom.Element element, final String attr, int def)

Here you can find the source of getInteger(final org.w3c.dom.Element element, final String attr, int def)

Description

Returns the integer value of the given XML attribute; or the default value.

License

Open Source License

Declaration

public static int getInteger(final org.w3c.dom.Element element, final String attr, int def) 

Method Source Code

//package com.java2s;

public class Main {
    /**/* w  w  w  .  j a  va  2 s  .c  o  m*/
     * Returns the integer value of the given XML attribute; or the default value.
     */
    public static int getInteger(final org.w3c.dom.Element element, final String attr, int def) {
        if (element.getAttributeNode(attr) == null)
            return def;

        try {
            return Integer.parseInt(element.getAttribute(attr).trim());
        } catch (NumberFormatException e) {
            // no exceptiion handling required
            return def;
        }
    }
}

Related

  1. getIntAttribute(Element element, String attribute)
  2. getIntAttribute(Element element, String name, int defaultValue)
  3. getIntAttribute(NamedNodeMap namedNodeMap, String name)
  4. getIntAttributeIgnoreCase(Element ele, String attr, int defaultvalue)
  5. getIntAttributeValue(Element element, String attribute)
  6. getIntegerAttribute(Element el, String attribute)
  7. getIntegerAttribute(Element element, String name)
  8. getStringAttr(Element element, String name, String def)
  9. getStringAttribute(Element e, String name, String def)