Java XML Attribute Read readBooleanAttribute(Element elem, String name, boolean defaultValue)

Here you can find the source of readBooleanAttribute(Element elem, String name, boolean defaultValue)

Description

read Boolean Attribute

License

Open Source License

Declaration

public static boolean readBooleanAttribute(Element elem, String name, boolean defaultValue) 

Method Source Code


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

public class Main {
    public static boolean readBooleanAttribute(Element elem, String name, boolean defaultValue) {
        boolean back = defaultValue;

        String str = elem.getAttribute(name);
        if (str != null) {
            if (str.length() > 0) {
                int hash = str.hashCode();
                if ((hash == "yes".hashCode()) || (hash == "true".hashCode())) {
                    back = true;//ww  w  .j av  a  2 s . c om
                } else {
                    back = false;
                }
            }
        }

        return back;
    }
}

Related

  1. getOptionalAttributeValue(NamedNodeMap attrs, String name)
  2. readAttribute(Node element, String attributeName)
  3. readAttribute(Node node, String attribute, String defaultValue)
  4. readAttributeWithPrefix(Node node, String attributePrefix, String defaultValue)
  5. readBoolAttr(Element element, String attributeName)
  6. readBooleanAttributeElement(final XMLStreamReader reader, final String attributeName)
  7. readFloat(Node node, String attributeName, float def)
  8. readFloatAttribute(XMLStreamReader reader, String attributeName)
  9. readInt(Node node, String attributeName, int def)