JXPathライブラリを見てください。JXpath を使用すると、Xpath クエリを使用してオブジェクトのグラフを検索できます。
zipCode=90210 ですべてのアドレスを検索する次の例を検討してください。
Address address = (Address)JXPathContext.newContext(vendor).
getValue("locations[address/zipCode='90210']/address");
この XPath 式は、次の Java コードと同等です。
Address address = null;
Collection locations = vendor.getLocations();
Iterator it = locations.iterator();
while (it.hasNext()){
Location location = (Location)it.next();
String zipCode = location.getAddress().getZipCode();
if (zipCode.equals("90210")){
address = location.getAddress();
break;
}
}