OK, now this is working as I want it. I was missing this, should have had a closer look into JavaDoc :-)

Thanks again!

Upayavira schrieb:

You need to query a resource, rather than a collection. Here's some code in Cocoon that'll do it. Check out the resourceToSAX method, and the associated queryToSAX() method.

http://cvs.apache.org/viewcvs.cgi/cocoon-2.1/src/blocks/xmldb/java/org/apache/cocoon/components/source/impl/XMLDBSource.java


Upayavira

Wolfram Horwath wrote:

Maybe I'm doing it wrong, but it doesn't seem to work.
So here's what I'm doing:

I have a class XmlDB which has a method open() and query(xpath):

public void open () {
     try {
        String driver = "org.apache.xindice.client.xmldb.DatabaseImpl";
        Class c = Class.forName(driver);

        Database database = (Database) c.newInstance();
        DatabaseManager.registerDatabase(database);

        String url = protocol + dbhost + collection;

dbCollection = DatabaseManager.getCollection(url);
} catch (XMLDBException xmle) {
System.err.println("XML:DB Exception occured " + xmle.errorCode);
} catch (Exception e) {
e.printStackTrace();
}
}


public ResourceSet query (String xpath) {
ResourceSet rs = null;
try {
XPathQueryService service =
(XPathQueryService) dbCollection.getService("XPathQueryService",
"1.0");
rs = service.query(xpath);
} catch (XMLDBException xmle) {
xmle.printStackTrace();
}
return (rs);
}


The collection I work on is /db/upro with documents having labels like klasse0.xml.
With collection.listResources() I try to get a list of all documents in the collection, to query each one afterwards.


When I try to set the collection to /db/upro/klasse0.xml for my following query I get a NullPointerException, when trying to query with /db/upro/klasse0.xml/some/more or /klasse0.xml/some/more or similar, on collection /db/upro, just nothing happens.

So, any hints what I am doing wrong?

Wolfram Horwath schrieb:

I wasn't aware if this was possible as it's not mentioned anywhere in the documentation. I thought of this possibility but wanted confirmation, so I'm going to try it that way.

Thanks for your help!

Wolfram

Upayavira schrieb:

Wolfram Horwath wrote:

Hi!

Is there a way to execute a XPATH-Query on only one specified document in a collection?





Erm. Isn't this easy? /db/collection/#//xpath does an Xpath on a collection, whereas /db/collection/document#//xpath does one on a document in a collection.


Am, I missing something?

Upayavira










Reply via email to