Java XML Attribute Get getAttributeAsBoolean(Element element, String attrName, boolean defValue)

Here you can find the source of getAttributeAsBoolean(Element element, String attrName, boolean defValue)

Description

Get the value of the given attribute of this Element as a boolean value.

License

Open Source License

Parameter

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

Return

Returns true if an attribute is found, whose value is 'true' Returns false if an attribute is found, whose value is 'false' Returns defValue otherwise.

Declaration

public static final boolean getAttributeAsBoolean(Element element, String attrName, boolean defValue) 

Method Source Code

//package com.java2s;

import org.w3c.dom.Element;

public class Main {
    /**/*from  w ww  .  j a va2s  . com*/
     * Get the value of the given attribute of this Element as a boolean value.
     * 
     * @param element
     *            Element
     * @param attrName
     *            name of the attribute to parse
     * @param defValue
     *            Default Boolean value if a valid Boolean text not found.
     * 
     * @return Returns true if an attribute is found, whose value is 'true' Returns false if an attribute is found,
     *         whose value is 'false' Returns defValue otherwise.
     */
    public static final boolean getAttributeAsBoolean(Element element, String attrName, boolean defValue) {
        String value = element.getAttribute(attrName);

        try {
            if ((value != null) && (value.length() > 0)) {
                return Boolean.valueOf(value).booleanValue();
            }
        } catch (Exception ex) {
        }

        return defValue;
    }
}

Related

  1. getAttribute(String name, Element element)
  2. getAttribute(String name, Element firstElement, Element secondElement)
  3. getAttribute(String name, Node node)
  4. getAttributeAsBoolean(Element elem, String attribName)
  5. getAttributeAsBoolean(Element element, String attrName, boolean defValue)
  6. getAttributeAsBoolean(Element element, String name)
  7. getAttributeAsBoolean(NamedNodeMap map, String name)
  8. getAttributeAsInteger(Element element, String attrName, Integer defValue)
  9. getAttributeAsLong(Element element, String attrName, Long defValue)