Java tutorial
//package com.java2s; import java.util.NoSuchElementException; import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class Main { public static Element firstChildElement(Element element, String childNameSpace, String childName) throws NoSuchElementException { NodeList childCandidateList; if (childNameSpace == null || childNameSpace.isEmpty()) { childCandidateList = element.getElementsByTagName(childName); } else { /*childCandidateList = element.getElementsByTagNameNS(childNameSpace, childName);*/ childCandidateList = element.getElementsByTagNameNS(childNameSpace, childName); } if (childCandidateList.getLength() > 0) { Element firstChild = (Element) childCandidateList.item(0); return firstChild; } else { throw new NoSuchElementException("No child candidate found in this element"); } } public static Element firstChildElement(Element element, String childName) throws NoSuchElementException { return firstChildElement(element, null, childName); } }