Here you can find the source of getChildTextAsBoolean(Element parent, String childName, boolean defValue)
public static final boolean getChildTextAsBoolean(Element parent, String childName, boolean defValue)
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static final boolean getChildTextAsBoolean(Element parent, String childName, boolean defValue) { try {/*ww w . j a v a 2s .c o m*/ String value = getChildText(parent, childName); if (value != null) { if (value.trim().equals("1")) { return true; } if (value.trim().equals("0")) { return false; } return Boolean.valueOf(value).booleanValue(); } } catch (Exception ex) { } return defValue; } public static final String getChildText(Element parent, String childName) { Element childElement = getFirstLevelChildElementByTagName(parent, childName); if (childElement != null) { return getText(childElement); } return null; } public static String trim(String input) { if (input == null) { return input; } return input.trim(); // int len = input.length(); // // int index = 0; // // for(index = 0;index < len;index++) // { // if(!Character.isWhitespace(input.charAt(index))) // { // break; // } // } // // return (index == 0) ? input : input.substring(index); } public static final Element getFirstLevelChildElementByTagName(Element parent, String elementName) { Node childNode = parent.getFirstChild(); while (childNode != null) { if ((childNode.getNodeType() == Node.ELEMENT_NODE) && ((Element) childNode).getLocalName().equals(elementName)) { return (Element) childNode; } childNode = childNode.getNextSibling(); } return null; } public static final String getText(Element elem) { if (elem != null) { NodeList childNodes = elem.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { if (childNodes.item(i).getNodeType() == Node.TEXT_NODE) { return trim(childNodes.item(i).getNodeValue()); } } } return null; } }