This isn't a bug, it's how it was designed. getID returns the ID only on resources that are actually documents, getDocumentID always returns the id for the document that contains returned resource. Basically if a node (i.e. resource) is retrieved from deep within the document then getID will return null, because that resource does not have an id. However, that resource is part of a document so if you do want to find out what document it is in you can call getDocumentID. If the retrieved resource is an actual document instance (i.e. you used Collection.getDocument() to get it) then both getID and getDocumentID will return the same thing. It's confusing, I know.

On Wednesday, December 18, 2002, at 06:31  AM, James Bates wrote:

On Wednesday 18 December 2002 13:12, Vladimir R. Bossicard wrote:
It's far less fancy than discovering how Xindice works or integrating it
into the latest container server but I've finally decided -instead of -1
everything- to help the users and write an "embed driver tutorial".
And fix bugs along the way (it looks like we still have a few).


With the following code

      String xpath_query = "//person[first='John']";
      XPathQueryService xpath = (XPathQueryService)
col.getService("XPathQueryService", "1.0");
      ResourceSet resultSet = xpath.query(xpath_query);

      ResourceIterator results = resultSet.getIterator();
      Resource res = results.nextResource();
      out.println("Result from the query:");
      out.println("   content: " + res.getContent());
      out.println("   id     : " + res.getId());

the output is

Result from the query:
content: <person xmlns:src="http://xml.apache.org/xindice/Query";
src:col="/db/example"
src:key="00000000485bce48000000f2314ce5a7"><first>John</ first><last>Doe</la
st><phone


type="home">555-123-456</phone><phone
type="work">555-456-789</phone></person>
     id     : null

Well, getId() returns null.  I have almost no doubt that this is a bug
but I am surprised the noone ever noticed it.


The problem is in
org.apache.client.xmldb.embed.CollectionImpl.query(), line 457. For some
reason XMLResourceImpl's make a distinction between "documentId" and simply
"Id". The above line sets id to NULL and documentId to the src:key attribute
of the result.


Exactly the same occurs with the XML-RPC driver in
org.apache.client.xmldb.xmlrpc.CollectionImpl.query(), line 559.

We should try and find out why there are separate id's and documentId's...

James



-Vladimir


Kimbro Staken
Java and XML Software, Consulting and Writing http://www.xmldatabases.org/
Apache Xindice native XML database http://xml.apache.org/xindice
XML:DB Initiative http://www.xmldb.org




Reply via email to