public static Element getUniqueChild ( Element element , String tagName ) throws Exception { Iterator goodChildren = getChildrenByTagName ( element , tagName ) ; if ( goodChildren != null && goodChildren . hasNext ( ) ) { Element child = ( Element ) goodChildren . next ( ) ; if ( goodChildren . hasNext ( ) ) { throw new Exception ( "expected only one " + tagName + " tag" ) ; } return child ; } else { throw new Exception ( "expected one " + tagName + " tag" ) ; } }
Gets the child of the specified element having the specified unique name . If there are more than one children elements with the same name and exception is thrown .