[jdom-interest] Finding XPath location for an Element

Paul Libbrecht paul at hoplahup.net
Tue Jan 10 11:37:32 PST 2012


Isn't the trick to compute the index as in b[0] ??
Lists of jdom using indexOf, elementA.getChildren('b').indexOf(elementB) are perfect for this.

paul


Le 10 janv. 2012 à 20:07, Rolf Lear a écrit :

> 
> Hi Cliff
> 
> No method 'native' to JDOM, but the code is simple (and you can 'season'
> to taste...):
> 
> String xpath = "";
> Element p = element;
> while (p != null) {
>  xpath = "/" + p.getName() + xpath;
>  p = p.getParentElement();
> }
> System.out.println(xpath);
> 
> But, the problem is that this will get *all* 'd' Elements that have an
> ancestry with the same XPath
> 
> Rolf
> 
> On Tue, 10 Jan 2012 13:46:07 -0500, cliff palmer <palmercliff at gmail.com>
> wrote:
>> I'd like to be able to find the XPath search or the node hierarchy for
>> an Element.  For example, if the Element is <d> in:
>> <a>
>>    <b>
>>           <c>
>>                 <d> </d>
>>           </c>
>>     </b>
>> </a>
>> 
>> I'd like to have either the XPath search argument ("/a//b//c//d) or
>> the list of nodes in the elements parents ("a b c d").
>> 
>> Is there a method that returns this?
>> 
>> Cliff
>> _______________________________________________
>> To control your jdom-interest membership:
>> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com




More information about the jdom-interest mailing list