public Element findElementById ( final String id ) { Element element = cache . get ( id ) ; if ( element == null ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "Search for element with ID {}" , id ) ; } Element root = document . getRootElement ( ) ; element = search ( root , elementName , idAttributeName , id ) ; if ( element != null ) { cache . put ( id , element ) ; } } return element ; }
Searches first in the cache for the given id . If it is found the element saved there will be returned . If it is not found the search - starting at the RootElement - will continue until the first element in the tree hierarchy is found which 1 . has the attribute id and 2 . whose id attribute has the value of the parameter s id . Once found it will be saved in the cache .