Java tutorial
//package com.java2s; import java.io.*; import org.w3c.dom.*; public class Main { public static final Element getElementByTagName(Element parent, String name) throws IOException { final NodeList list = parent.getElementsByTagName(name); if (list.getLength() == 1) { return (Element) list.item(0); } else { throw new IOException(String.format("Expected one child element named \"%s\"", name)); } } }