Here you can find the source of getAttributeValueBoolean(Node node, String attrName)
Parameter | Description |
---|---|
node | The node to extract attribute from |
attrName | The name of the attribute |
Parameter | Description |
---|---|
NullPointerException | If <code>node</code> is <code>null</code> |
false
if such attribute does not exist
public static boolean getAttributeValueBoolean(Node node, String attrName)
//package com.java2s; /*//w w w. j a v a 2 s .c o m * Copyright (C) 2016 Alexander Vasilevsky * * This program 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. * * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */ import org.w3c.dom.Node; public class Main { /** * Returns boolean value of the named attribute of the node. * Returns <code>true</code> if attribute value equals "true" * ignore case or "1". Otherwise, returns <code>false</code>. * * @param node The node to extract attribute from * @param attrName The name of the attribute * * @return Boolean value of the attribute or <code>false</code> * if such attribute does not exist * * @throws NullPointerException If <code>node</code> is <code>null</code> */ public static boolean getAttributeValueBoolean(Node node, String attrName) { String value = getAttributeValue(node, attrName); return "true".equalsIgnoreCase(value) || "1".equals(value); } /** * Returns string value of the named attribute of the node. * Returns <code>null</code> if such attribute does not exist. * * @param node The node to extract attribute from * @param attrName The name of the attribute * * @return String value of the attribute or <code>null</code> * * @throws NullPointerException If <code>node</code> is <code>null</code> */ public static String getAttributeValue(Node node, String attrName) { Node attr = node.getAttributes().getNamedItem(attrName); return attr == null ? null : attr.getNodeValue(); } }