[jdom-interest] newbie question

Laurent Bihanic laurent.bihanic at atosorigin.com
Wed Dec 4 06:35:14 PST 2002

Robert Koberg wrote:
> Is there something about JDOM that makes XPath in Java much better performing
> than using DOM? Or by using XPath do you have the same problems (memory) that
> you have with DOM?

I agree that XPath is probably not the fastest (CPU-wise) solution but why do 
you think XPath can lead to memory problems?
The XPath engine allocates memory when it compiles the XPath expression (when 
you invoke XPath.newInstance) but not when evaluating the expression against a 
given node. At this stage, it just navigates the document.
There's one exception to the above rule in Jaxen: Namespaces. When evaluating 
namespaces, the XPath engine allocates wrapper objects as XPath Namespaces do 
have a parent while JDOM's don't.

As for speed, you can reach quite good performances by compiling XPath 
expressions and reusing them (i.e. using XPath.newInstance rather than the 
static selectNodes and selectSingleNode). If need be, you can use XPath 
variables in your expressions to use few generic compiled XPaths and call 
setVariable to "adapt" the expression before each evaluation.


More information about the jdom-interest mailing list