You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-users@xml.apache.org by Gul Akbar <G....@Bradford.ac.uk> on 2003/04/04 15:08:51 UTC
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
RE: Getting ID for a retrieved document
Posted by Gul Akbar <G....@Bradford.ac.uk>.
That has done it.
Thanks
Gul Akbar
Quoting Kevin Ross <Ke...@iVerticalLeap.com>:
> 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:G.Akbar@Bradford.ac.uk]
> Sent: Friday, April 04, 2003 7:09 AM
> To: xindice-dev@xml.apache.org
> 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
RE: Getting ID for a retrieved document
Posted by Kevin Ross <Ke...@iVerticalLeap.com>.
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:G.Akbar@Bradford.ac.uk]
Sent: Friday, April 04, 2003 7:09 AM
To: xindice-dev@xml.apache.org
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