[jdom-interest] XPath from Element

Jason Hunter jhunter at servlets.com
Wed Jul 16 20:58:43 PDT 2003


There's no direct method.  It'd be easy to write by walking up the tree 
and counting your place along the way.  Of course, the only path you can 
get from a tool is fragile and based on things like index which aren't 
the kind of general XPath a person can write which more describes the 
element's characteristics than it's current locatoin.

Why do you need this?

-jh-

Todd O'Bryan wrote:

> I'm using XML to write a mini-programming language (very mini), but I 
> need to be able to catch syntax errors and tell the user where they occur.
> 
> Is there a way to get an XPath representation of an Element from the 
> element?
> 
> For example,
> 
> <x>
>     <y>
>         <z>...</z>
>         <z>...</z>
>         <z>Error here</z>
>     </y>
> </x>
> 
> When I discover the error processing the element shown, is there any way 
> to get
> /x/y/z[2] from somewhere?
> 
> Thanks,
> Todd
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com 
> 
> 




More information about the jdom-interest mailing list