Java XML Attribute Get getBooleanAttribute(Element element, String name, boolean defaultValue)

Here you can find the source of getBooleanAttribute(Element element, String name, boolean defaultValue)

Description

Get the value of an attribute of the given element with the given name as a boolean, or return the given default value if the attribute is missing or not parseable as a boolean.

License

Open Source License

Parameter

Parameter Description
element the element in which to find the attribute
name the name of the attribute
defaultValue the value to return if the attribute value is not parseable as a boolean

Return

the boolean value of the attribute, or the default value

Declaration

public static boolean getBooleanAttribute(Element element, String name, boolean defaultValue) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2009, 2011 The University of Memphis.  All rights reserved. 
 * This program and the accompanying materials are made available 
 * under the terms of the LIDA Software Framework Non-Commercial License v1.0 
 * which accompanies this distribution, and is available at
 * http://ccrg.cs.memphis.edu/assets/papers/2010/LIDA-framework-non-commercial-v1.0.pdf
 *******************************************************************************/

import org.w3c.dom.Element;

public class Main {
    /**//w ww.j  a  v a 2  s . c  o m
     * Get the value of an attribute of the given element with the given name as
     * a boolean, or return the given default value if the attribute is missing
     * or not parseable as a boolean. The {@link Boolean#parseBoolean} method is
     * used to parse the value.
     * 
     * @param element
     *            the element in which to find the attribute
     * @param name
     *            the name of the attribute
     * @param defaultValue
     *            the value to return if the attribute value is not parseable as
     *            a boolean
     * @return the boolean value of the attribute, or the default value
     */
    public static boolean getBooleanAttribute(Element element, String name, boolean defaultValue) {
        String s = element.getAttribute(name);
        if (s != null)
            return Boolean.parseBoolean(s);
        return defaultValue;
    }
}

Related

  1. getBooleanAttribute(Element elem, String attName, boolean mandatory)
  2. getBooleanAttribute(Element elem, String attName, boolean mandatory, boolean defaultValue)
  3. getBooleanAttribute(Element element, String attributeName)
  4. getBooleanAttribute(Element element, String key, boolean defValue)
  5. getBooleanAttribute(Element element, String name)
  6. getBooleanAttribute(Node n, String attributeName)
  7. getBooleanAttribute(Node targetElem, String keyName, boolean defaultValue)
  8. getBooleanAttributeByName(Node content, String attributeName, boolean defaultTrue)
  9. getBooleanAttributeOption(final Element configuration, final String option, boolean defaultValue)