Java XML Attribute Get getAttributeBoolean(Node node, String name)

Here you can find the source of getAttributeBoolean(Node node, String name)

Description

Gets the boolean value of a named attribute of a node.

License

CDDL license

Parameter

Parameter Description
node Node
name String

Return

boolean

Declaration

public static boolean getAttributeBoolean(Node node, String name) 

Method Source Code

//package com.java2s;
/*/*  w  w w .  jav  a2  s .com*/
Copyright (c) 2013 eBay, Inc.
This program is licensed under the terms of the eBay Common Development and
Distribution License (CDDL) Version 1.0 (the "License") and any subsequent  version 
thereof released by eBay.  The then-current version of the License can be found 
at http://www.opensource.org/licenses/cddl1.php and in the eBaySDKLicense file that 
is under the eBay SDK ../docs directory.
*/

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class Main {
    /**
     * Gets the boolean value of a named attribute of a node.
     * @param node Node
     * @param name String
     * @return boolean
     */
    public static boolean getAttributeBoolean(Node node, String name) {
        String s = getAttributeString(node, name);
        if (s != null && s.length() > 0) {
            return (s.compareToIgnoreCase("1") == 0);
        } else
            return false;
    }

    /**
     * Gets the value of a named attribute of a node.
     * @param node Node The context node.
     * @param name String
     * @return String null means node is not found.
     */
    public static String getAttributeString(Node node, String name) {
        Node nd = findAttribute(node, name);
        if (nd != null)
            return nd.getNodeValue();
        return null;
    }

    /**
     * Finds attribute of node by name.
     * @param node Node The context node.
     * @param name String
     * @return Node
     */
    public static Node findAttribute(Node node, String name) {
        Node found = null;
        NamedNodeMap nm = node.getAttributes();
        if (nm != null) {
            for (int i = 0; i < nm.getLength(); i++) {
                Node attr = nm.item(i);
                if (attr.getNodeName().compareToIgnoreCase(name) == 0) {
                    found = attr;
                    break;
                }
            }
        }
        return found;
    }
}

Related

  1. getAttributeBoolean(Element aElement, String aAttributeName)
  2. getAttributeBoolean(Element el, String label)
  3. getAttributeBoolean(final Element element, final String name)
  4. getAttributeBoolean(final Node node, final String name, final Boolean defaultValue)
  5. getAttributeBoolean(Node node, String attributeName)
  6. getAttributeBooleanByName(NamedNodeMap nnm, String name)
  7. getAttributeBooleanByName(NamedNodeMap nnm, String name)
  8. getAttributeByIndex(final Element element, final int index)
  9. getAttributeByLocalName(XMLStreamReader reader, String localName)