Java tutorial
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { /** * Loads an optional double element value from a XML element */ public static double getDoubleNode(Element element, String name) { Element child = getSingleElement(element, name); if (child == null) return 0.0; String value = child.getTextContent(); if (value == null) return 0.0; if (value.length() == 0) return 0.0; return Double.parseDouble(value); } /** * 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; } }