[jdom-interest] How Do I sue XPAth with JDOM

Laurent Bihanic laurent.bihanic at atosorigin.com
Fri Mar 21 08:16:53 PST 2003


Adam Flinton wrote:
> Are there any /where do I find the docs wrt spitting out the xpath to 
> the current element. i.e. imagine my code is working it's way down 
> through a JDOM tree checking the element /attibute values & it comes 
> across one which ain't right. I have the element so how do I get the 
> XPath to that element out as a string for putting into a log?

JDOM does not include any method to do that.
It's quite easy to write a method that will recursively build the path of a 
node using its position relative to its siblings within a given parent. But 
this type of XPath expression may no longer be valid once the document 
contents is altered.
The other solution is to build an XPath expression using ID-type attribute 
values. This type of expression will resist changes but requires a priori 
knowledge about the document structure and thus can not be made generic.

> Are there any docs about setting up JDOMb8 with any ancillary jars 
> (jaxen?) in order to get it to run ?

Jaxen 1.0 FCS binaries are included in the latest JDOM (not Beta 8 but the 
nightly builds). Just add the 3 JARs (jaxen-core.jar, jaxen-jdom.jar and 
saxpath.jar) in your classpath.

> Lastly...... is XPath part of the main JDOM code yet or is it an 
> "experimental fork" which is going to be brought into the main body of 
> the code once everyone's happy with it? If so when will / is it 
> scheduled for that to occur?

XPath is now part of JDOM core, again not beta 8 but the latest (a.k.a 
beta9-dev). See package org.jdom.xpath

Laurent




More information about the jdom-interest mailing list