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:
*
//[EMAIL PROTECTED] = 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("//[EMAIL PROTECTED] =
3]/..");
while (it.hasNext()) {
// Do something with every State having Country id = 3
}
Regards,
Nicolas Laplante