Java tutorial
//package com.java2s; import java.io.*; import java.util.*; import org.w3c.dom.*; public class Main { public static final Element getChildElement(Element parent) throws IOException { final List<Element> childElements = getChildElements(parent); if (childElements.size() == 1) { return childElements.get(0); } else { throw new IOException("Expected one child element"); } } public static final List<Element> getChildElements(Element parent) { final List<Element> childElements = new ArrayList<Element>(); final NodeList childNodes = parent.getChildNodes(); for (int i = 0; i < childNodes.getLength(); ++i) { final Node node = childNodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { childElements.add((Element) node); } } return childElements; } }