commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nicolas Laplante <nicolas.lapla...@gmail.com>
Subject JXPath nested property
Date Sat, 03 Feb 2007 01:29:50 GMT
Hi,

I have the following 2 bean definitions:

Country {
    int id;
    String name;
}

State {
    int id;
    String name;
    Country country;
}

If I have a *List<State>*, how can I get every state that has a 
*Country* having id = 2 ?

I tried the following XPath expression using the *List<State>* as the 
context:
*
//country[@id = 3]/.. *  (to fetch every state that have a *Country* 
with id = 3)

An iterator is returned, and as soon as I call *hasNext()*, I have the 
following exception:

*org.apache.commons.jxpath.JXPathException: Cannot compare pointers that 
do not belong to the same tree: '/.[2]' and '/.[1]'*

Here's the code sample:

JXPathContext ctx = JXPathContext.newContext(/* fetch the List<State> 
object here */);
Iterator<State> it = (Iterator<State>) ctx.iterate("//country[@id = 3]/..");
               
while (it.hasNext()) {
   // Do something with every State having Country id = 3
}

Regards,

Nicolas Laplante

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message