You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-users@xml.apache.org by Boris Rousseau <br...@tssg.org> on 2003/07/23 11:37:14 UTC
using Java to query the db
Hi all,
Using the developer guide, I am trying to use Java to query with XPath.
I am currently using Xindice version 1.1 and with the command line this works fine:
xindice xpath -c /db/addressbook -s "b=http://www.books.com/" -q //b:person[fname='John']
However, I wonder how do I specify a namespace in this following Java extract.
String driver = "org.apache.xindice.client.xmldb.DatabaseImpl";
Class c = Class.forName(driver);
Database database = (Database) c.newInstance();
DatabaseManager.registerDatabase(database);
col = DatabaseManager.getCollection("xmldb:xindice:///db/addressbook");
String xpath = "//person[fname='John']";
XPathQueryService service = (XPathQueryService) col.getService("XPathQueryService", "1.0");
ResourceSet resultSet = service.query(xpath);
ResourceIterator results = resultSet.getIterator();
while (results.hasMoreResources()) {
Resource res = results.nextResource();
System.out.println((String) res.getContent());
}
Can you help me figure this out?
Regards,
Boris