From: Marc T. <ti...@th...> - 2005-12-04 02:41:54
|
Hello, I am trying to perform a "nested" XPath query on an XMLResource result returned from an initial query. It seems to work fine if my return value does not include any "synthetic" XML, but once I introduce some wrapper XML, I am getting a NullPointerException. Here is a piece of sample code that reproduces the problem using the Mondial data set: --------------------------- public static void main(String args[]) throws Exception { Class cl =3D Class.forName("org.exist.xmldb.DatabaseImpl"); Database database =3D (Database)cl.newInstance(); DatabaseManager.registerDatabase(database); =20 Collection col =3D=20 DatabaseManager.getCollection( "xmldb:exist://localhost:8080/exist/xmlrpc/db" ); XPathQueryServiceImpl service =3D (XPathQueryServiceImpl) col.getService("XPathQueryService", "1.0"); =20 ResourceSet result =3D service.query("for $city in /mondial//city[name&=3D'tre*'] return <result>{$city}</result>"); =20 ResourceIterator i =3D result.getIterator(); while(i.hasMoreResources()) { =20 XMLResource r =3D(XMLResource) i.nextResource(); =20 //This next line throws a NullPointerException! ResourceSet result2 =3D service.query(r,"result/city"); =20 System.out.println(result2.getSize()); =20 System.out.println(r.getContent()); } }=20 -------------------------------- Note, if I take out the <result></result> and change the nested query to "city", it works like a charm. Also, if this is a newbie question, if I have missed something totally obvious, or there is a much better way to do this, please accept my apologies in advance... Any help would be greatly appreciated, Marc Tinkler ____________________________________________=20 TH!NKMAP=20 157 chambers st ny ny 10007 |