Here you can find the source of getBooleanAttributeRequired(Node node, String attributeName)
public static boolean getBooleanAttributeRequired(Node node, String attributeName) throws Exception
//package com.java2s; //License from project: Apache License import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { private static final String VALUE_TRUE = "true"; private static final String VALUE_FALSE = "false"; public static boolean getBooleanAttributeRequired(Node node, String attributeName) throws Exception { String string = getStringAttributeRequired(node, attributeName); if (VALUE_TRUE.equals(string)) { return true; } else if (VALUE_FALSE.equals(string)) { return false; }/*from w w w .ja v a 2s . c o m*/ throw new Exception("Could not read boolean from value '" + string + "' in attribute '" + attributeName + "' in node '" + node.getLocalName() + "'"); } public static String getStringAttributeRequired(Node node, String attributeName) throws Exception { NamedNodeMap attributes = node.getAttributes(); Node value = attributes.getNamedItem(attributeName); if (value == null) { throw new Exception("Missing attribute '" + attributeName + "' in node '" + node.getNodeName() + "'"); } String text = value.getTextContent(); if (text == null) { throw new Exception("Missing text '" + attributeName + "' in node '" + node.getNodeName() + "'"); } return text; } }