
	import org.xmldb.api.base.*;
	import org.xmldb.api.modules.*;
	import org.xmldb.api.*;
    
    public class show_xml 
    {

@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
      Collection col = null;
      try {
    	//define the driver to connect to XIndice database      
    	  String driver = "org.apache.xindice.client.xmldb.DatabaseImpl";
         Class c = Class.forName(driver);

         Database database = (Database) c.newInstance();
         DatabaseManager.registerDatabase(database);
        // define the path of the collection which contains the persons.xml file
         col = DatabaseManager.getCollection("xmldb:xindice:///db/Test");
         System.out.println("col:"+col.getName());
        // specify the xpath expression to execute 
         String xpath = "//person/fname";
         XPathQueryService service =
            (XPathQueryService) col.getService("XPathQueryService", "1.0");
         //store the result of the xpath expression in a resultset
         ResourceSet resultSet = service.query(xpath);
         // specify an iterator of the result
         ResourceIterator results = resultSet.getIterator();
         
         do  {
            Resource res = results.nextResource();
         // show element of each resource
            System.out.println((String) res.getContent());
         }while(results.hasMoreResources());
      }
      catch (XMLDBException e) {
         System.err.println("XML:DB Exception occured " + e.errorCode);
      }
      finally {
         if (col != null) {
            col.close();
         }
      }
   }
}
