Java XML Attribute Get getBoolAttribute(Node node, String name, boolean defVal)

Here you can find the source of getBoolAttribute(Node node, String name, boolean defVal)

Description

get Bool Attribute

License

Open Source License

Declaration

public static boolean getBoolAttribute(Node node, String name, boolean defVal) 

Method Source Code

//package com.java2s;
/*/*www. j  av  a  2  s .c o  m*/
 * Radakan is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Radakan is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Radakan.  If not, see <http://www.gnu.org/licenses/>.
 */

import org.w3c.dom.Node;

public class Main {
    public static boolean getBoolAttribute(Node node, String name) {
        return Boolean.parseBoolean(getAttribute(node, name));
    }

    public static boolean getBoolAttribute(Node node, String name, boolean defVal) {
        String att = getAttribute(node, name);
        if (att == null)
            return defVal;
        return Boolean.parseBoolean(att);
    }

    /**
     * Returns an attribute of the specified tag with the name provided.
     * 
     * @param node
     * @param name
     * @return The attribute if its defined, or null.
     */
    public static String getAttribute(Node node, String name, String defVal) {
        Node att = node.getAttributes().getNamedItem(name);
        return att == null ? defVal : att.getNodeValue();
    }

    public static String getAttribute(Node node, String name) {
        return getAttribute(node, name, null);
    }
}

Related

  1. getBeanclassAttribute(Node node)
  2. getBool(Element el, String attrName, boolean defaultValue)
  3. getBoolAttribute(NamedNodeMap namedNodeMap, String name)
  4. getBoolAttribute(Node node, String attr)
  5. getBoolAttribute(Node node, String name)
  6. getBoolean(Element element, String attribute, boolean defaultValue)
  7. getBooleanAttr(Element element, String name)
  8. getBooleanAttrib(Element element, String attribName, String namespaceURI)
  9. getBooleanAttribute(Element e, String name)