Re: Finding XPath location for an Element
Rolf Lear <[email protected]>
| Newsgroups | gmane.comp.java.jdom.general |
|---|---|
| Message-ID | <[email protected]> |
Yes, you could do that and get an exact path to a particular element.... I had not thought it through as far as you, but the indexing is reasonable (so is 'season to taste').... But then you should probably also take it further again and ensure that the namespace management is correct too.... but how would you set up the XPath references/links for an XPath query with namespaces ... easily ... and in a 'general' way? Rolf On Tue, 10 Jan 2012 20:37:32 +0100, Paul Libbrecht <[email protected]> wrote: > 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 <[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] _______________________________________________ To control your jdom-interest membership: http://www.jdom.org/mailman/options/jdom-interest/[email protected]