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 David Cahill <da...@may.ie> on 2002/11/13 16:27:42 UTC
Xindice manipulation
I'm attempting to adapt the example1.java program that accompanys Xindice to
manipulate my own "handbook.xml" file which I placed within the addressbook
collection in Xindice. I'm attempting to access the "Handbook" element &
match the value contained within the "email" attribute which itself is
contained within the "departmental-office" attibute. When i run this
program it compiles but I'm not getting any output. Can you see where I'm
going wrong?
Cheers,
David
Here is my XML file:
*********************************************************
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSPY v5 U (http://www.xmlspy.com) -->
<Handbook xmlns="http://www.cs.may.ie/namespace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.cs.may.ie/namespace
C:\thesis\xml\handbookfirst.xsd">
<Welcome>blah blah blah </Welcome>
<Departmental_Office>
<Info>The Computer Science Departmental Office is located on the first
floor at the end of the Callan Extension (Room 2.118). Reference the maps at
the end of the handbook.
The office is open from 9.30-1.00 and 2.30-5.00.
Contact information:
</Info>
<postal_address>Department of Computer Science
National University of Ireland, Maynooth
Maynooth
Co. Kildare
</postal_address>
<email> admin@college.ie</email>
<telephone>7689442</telephone>
</Departmental_Office>
<Useful_Dates>2002
September 23rd - Semester 1 starts
December 20th - Semester 1 ends
December - Semester 1 Exams (MScSE/HDIPSE)
2003
</Useful_Dates>
<COURSE-DIRECTORS-AND-YEAR-COORDINATORS-FOR-2002-2003>
blah blah blah</COURSE-DIRECTORS-AND-YEAR-COORDINATORS-FOR-2002-2003>
</Handbook>
*****************************************************
Here is the Java program I'm running
*************************************************
import org.xmldb.api.base.*;
import org.xmldb.api.modules.*;
import org.xmldb.api.*;
public class test {
public static void main(String[] args) throws Exception {
Collection col = null;
try {
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 =
"/Handbook/Departmental_Office[email='admin@college.ie']";
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());
}
}
catch (XMLDBException e) {
System.err.println("XML:DB Exception occured " + e.errorCode);
}
finally {
if (col != null) {
col.close();
}
}
}
}