[jdom-interest] Xpath support
Laurent Bihanic
laurent.bihanic at atosorigin.com
Fri Dec 5 05:09:30 PST 2003
On 05/12/2003 08:45, Edward Barrow wrote:
> What I would like is a way to get a node's absolute xpath (I'd be
> satisfied if it only worked with Elements, but nodes would be better) -
>
> eg: XPath xpath = element.getXPath();
>
> or XPath.getXpath(element).
>
> Or is there an easy way to do that already, that I just can't find?
You could try the XPathHelper class from the org.jdom.contrib.helpers package
in the jdom-contrib module from CVS:
String xpath = XPathHelper.getPathString(element);
The reason this code is not part of the XPath class is that it returns XPath
expressions that are dependent on the document structure. Add, remove or
rename a node and the generated XPaths won't work any longer.
Thus, these XPaths are very short lived. For long term XPath, you should use
XPaths that are based on the semantics of the document.
Laurent
More information about the jdom-interest
mailing list