public static Element search ( final Element root , final String elementName , final String idAttributeName , final String id ) { Element element = null ; @ SuppressWarnings ( "unchecked" ) List < Element > children = root . getChildren ( ) ; for ( Element e : children ) { if ( elementName == null || e . getName ( ) . equals ( elementName ) ) { Attribute a = e . getAttribute ( idAttributeName ) ; if ( a != null && id . equals ( a . getValue ( ) ) ) { element = e ; } else { element = search ( e , elementName , idAttributeName , id ) ; } } if ( element != null ) { break ; } } return element ; }
Searches the ElementBaum starting with the given element for the ChildElement with the respective attribute value