Java XML Attribute Get getAttributeBoolean(Element aElement, String aAttributeName)

Here you can find the source of getAttributeBoolean(Element aElement, String aAttributeName)

Description

Returns the boolean value of the specified attribute from the given Element.

License

Open Source License

Parameter

Parameter Description
aElement The owning <code>Element</code>.
aAttributeName The name of the attribute.

Return

boolean if the attribute has the value of "true" then true, else false

Declaration

public static boolean getAttributeBoolean(Element aElement,
        String aAttributeName) 

Method Source Code

//package com.java2s;
import org.w3c.dom.*;

public class Main {
    /**//from   ww w .  ja v  a 2s .c om
     * Returns the <code>boolean</code> value of the specified attribute from the given Element.
     *
     * @param aElement       The owning <code>Element</code>.
     * @param aAttributeName The name of the attribute.
     * @return boolean if the attribute has the value of "true" then true, else false
     */
    public static boolean getAttributeBoolean(Element aElement,
            String aAttributeName) {
        return "true".equals(getAttribute(aElement, aAttributeName)); //$NON-NLS-1$
    }

    /**
     * Returns the <code>boolean</code> value of the specified attribute from the given Element.
     * If the attribute is empty then the default value is returned.
     *
     * @param aElement The owning <code>Element</code>.
     * @param aAttr    The name of the attribute.
     * @param aDefault The default value if the attribute value is empty.
     * @return boolean
     */
    public static boolean getAttributeBoolean(Element aElement,
            String aAttr, boolean aDefault) {
        String boolStr = aElement.getAttribute(aAttr);
        return boolStr.equals("") ? aDefault : getAttributeBoolean(aElement, aAttr); //$NON-NLS-1$
    }

    /**
     * Returns the value of the specified attribute from the given Element.
     *
     * @param aElement       The owning <code>Element</code>.
     * @param aAttributeName The name of the attribute.
     * @return String
     */
    public static String getAttribute(Element aElement,
            String aAttributeName) {
        return aElement.getAttribute(aAttributeName);
    }

    /**
     * Retrieves the given attribute from the given Element.  If the attribute had an empty String
     * value then the default argument is returned.
     *
     * @param aElement The owning <code>Element</code>.
     * @param aAttr    The name of the attribute.
     * @param aDefault The default value if the attribute value is empty.
     */
    public static String getAttribute(Element aElement, String aAttr,
            String aDefault) {
        String str = getAttribute(aElement, aAttr);
        return str.equals("") ? aDefault : str; //$NON-NLS-1$
    }
}

Related

  1. getAttributeAsInteger(Element element, String attrName, Integer defValue)
  2. getAttributeAsLong(Element element, String attrName, Long defValue)
  3. getAttributeAsString(NamedNodeMap attributes, String name)
  4. getAttributeAsString(XMLStreamReader reader, String name)
  5. getAttributeAsURIString(XMLStreamReader reader, String name)
  6. getAttributeBoolean(Element el, String label)
  7. getAttributeBoolean(final Element element, final String name)
  8. getAttributeBoolean(final Node node, final String name, final Boolean defaultValue)
  9. getAttributeBoolean(Node node, String attributeName)