That has done it.
Thanks
Gul Akbar
Quoting Kevin Ross <[EMAIL PROTECTED]>:
> This is indeed an oddity in the design of the xmldb api. Clearly it
> causes much confusion, as it did for me too. I received some of this
> code on the list. Here, you can see a function that will remove every
> doc obtained from any xpath query. This shows how to obtain the id
> from
> the ResourceSet.
>
> /**
> * Removes all resources returned by the query.
> *
> */
> public void remove(Collection collection, String xpath) throws
> Exception {
>
> //
> // We really have to do this in a bogus way to work
> around a problem with the xml:db api.
> // You cannot remove a resource from a
> collection when the resource is
> // obtained from an
> XPathQueryService.
> //
> ResourceSet resourceSet = loadResourceSet(collection,
> xpath);
> ResourceIterator resourceIterator =
> resourceSet.getIterator();
> while (resourceIterator.hasMoreResources()) {
> Resource res = resourceIterator.nextResource();
> if (res instanceof XMLResource) {
>
> // find the key (getId() doesn't work,
> apparently
> // because Resources from ResourceSets
> are "anonymous"?)
> Node xmldoc = ((XMLResource)
> res).getContentAsDOM().getFirstChild();
> NamedNodeMap attrs =
> xmldoc.getAttributes();
> Node keyNode =
> attrs.getNamedItemNS("http://xml.apache.org/xindice/Query", "key");
> String key = keyNode.getNodeValue();
>
> // now that we have the key, remove
> resource from collection
> Resource doc =
> collection.getResource(key);
> if (doc != null) {
> collection.removeResource(doc);
> }
> }
> }
> }
>
> -----Original Message-----
> From: Gul Akbar [mailto:[EMAIL PROTECTED]
> Sent: Friday, April 04, 2003 7:09 AM
> To: [EMAIL PROTECTED]
> Subject: Getting ID for a retrieved document
>
> Hi,
>
> How do I get the ID from a Resource which I set when I added the
> record?
>
> Resource res = results.nextResource();
> String ID = res.getId();
>
> This returns the String ID as 'null' everytime!
>
>
> Thanks
> Gul
>
> -------------------------------------------------
> This mail sent through IMP: webmail.brad.ac.uk
>
>
>
-------------------------------------------------
This mail sent through IMP: webmail.brad.ac.uk