You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by David Cahill <vi...@yahoo.co.uk> on 2002/11/12 13:07:31 UTC

XML manipulation

I am trying to manipulate an xml document i placed within the addressbook collection in Xindice. I'm attempting to match the value contained within the email attribute in the departmental-office element.  When i run this script it compiles but I'm not getting any output. Can you see where I'm going wrong? 
Many thanks, 
David  
 
//package org.apache.xindice.examples;  /If I include this line the program wont compile 
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 = "//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();
         }
      }
   }
}




---------------------------------
Get a bigger mailbox -- choose a size that fits your needs.