[jdom-interest] Related to JDOM - Jaxen performance and selectSingleNode api

Laurent Bihanic laurent.bihanic at atosorigin.com
Tue Apr 27 06:13:39 PDT 2004

Elliotte Rusty Harold wrote:
> Don't use selectSingleNode. It's hard to tell without knowing more about 
> your use case, but I suspect you can reduce this to one or a few calls 
> to selectNodes (Or whatever Jaxen calls that functionality) that return 
> a list you them iterate through, so you don't keep searching the 
> document every time.

I agree. In Jaxen 1.0 FCS, selectSingleNode performs a selectNodes call and 
returns only the first object in the list.
Thus, selectSingleNode performs a full document scan instead of stopping once 
the first matching node is found as one would expect.

To fix such a performance issue, you should use XPath expressions that narrow 
the scope of search. Especially avoid expressions such as "//myNode" which 
will force a full document search. Prefer "/nodeA/nodeB//myNode".


More information about the jdom-interest mailing list