Re: Finding XPath location for an Element
Rolf Lear <[email protected]>
| Newsgroups | gmane.comp.java.jdom.general |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]>
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/[email protected]
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/[email protected]