Java tutorial
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { /** * Loads an optional Boolean element value from a XML element */ public static boolean getBooleanNode(Element element, String name, boolean _default) { Element child = getSingleElement(element, name); if (child == null) return _default; String value = child.getTextContent(); if (value == null) return _default; if (value.compareTo("S") == 0) return true; if (value.compareTo("N") == 0) return false; return _default; } /** * Returns a single element having a given tag */ public static Element getSingleElement(Element element, String tagName) { Node node = element.getFirstChild(); while (node != null) { if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().compareTo(tagName) == 0) return (Element) node; node = node.getNextSibling(); } return null; } }