Java tutorial
//package com.java2s; import org.w3c.dom.*; public class Main { /** * @return the child element, throws exception if the parent does not * have exactly one sub element with name */ public static Element getSingleSubElement(Element parentElement, String name) { NodeList nodes = parentElement.getElementsByTagName(name); if (nodes.getLength() != 1) { throw new IllegalArgumentException("Expected the element " + parentElement.getNodeName() + " to have one child called " + name + " but found " + nodes.getLength()); } return (Element) nodes.item(0); } }