> I know of no other way, nature of the beast...

A more elegant way is transforming the result in JDOM
- http://www.jdom.org (or another DOM) and using the
associated API.
Example:

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.JDOMException;

import org.xmldb.api.base.*;
import org.xmldb.api.modules.*;
import org.xmldb.api.*;

...

ResourceSet resultSet = this.service.query(this.xpathQuery);
ResourceIterator results = resultSet.getIterator();
while (results.hasMoreResources()) {
   Resource res = results.nextResource();
   String resu = (String) res.getContent();

   // create JDOM Element
   Element resultElement = jdomEl(resu);
   ...
}


private Element jdomEl(String xmlInput) throws JDOMException {
   Element el = new Element("dummy");
   try {
      SAXBuilder builder = new SAXBuilder(false);
      Document doc = builder.build(new StringReader(xmlInput));
      el = (Element)doc.getRootElement().clone();
   } catch (JDOMException e) {
      e.printStackTrace();
   } finally {
      return el;
   }
}



Carsten



Am 25.04.2002 20:04 Uhr schrieb "Mark J. Stang" unter
<[EMAIL PROTECTED]>:

> nani,
> The result of an XPathQueryResult is a document.   You have to parse that
> resulting document to get your result.   The result will contain the key that
> matches your XPath Query.   If you search on an attribute, you will get back
> the element that contains that attribute.  Therefore, a search on
> //*/[EMAIL PROTECTED]
> will return an XML document that contains the <ccc value="Hello"></ccc> the
> collection it came from and the key to the document that contains the element.
> 
> You will have to parse the document to get the key and the "attributes">.
> Since the format is the same, this can be done fairly easily with a SAX
> parser.
> I know of no other way, nature of the beast...
> 
> HTH,
> 
> Mark
> 
> Jayaram Narayana wrote:
> 
>> =============================================================
>> this question has been posted to the xindice dev. forum also.
>> =============================================================
>> 
>> hi there,
>> 
>> using an xpath query returns a lot more information than what's actually
>> required. example, given an element that looks like this:
>> 
>> <aaa>
>>         <bbb>
>>         <ccc value = "Hello">
>> </aaa>
>> 
>> and an xpath query like this:
>> "//ccc [EMAIL PROTECTED]"
>> 
>> will return a big result like this:
>> 
>> <aaa xmlns:src="http://xml.apache.org/xindice/Query"; src:col="/db/zzz/yyy"
>> src:key="eee">
>>  <ccc value="Hello" />
>> </aaa>
>> 
>> all i am interested in is the value of the attribute "value" (Hello). how
>> can i get JUST that directly, and nothig else? i do not want to parse the
>> DOM for this.
>> 
>> TIA,
>> -nani
> 
> 


--

Medizinische Hochschule Hannover                    Fachhochschule Hannover
Abt. H�matologie und Onkologie     FB Informations- und Kommunikationswesen
Carl-Neuberg-Stra�e 1                               Ricklinger Stadtweg 120
30625 Hannover                                               30459 Hannover

                           ++49-511-9296-1650
                    http://summit-bmt.fh-hannover.de





Reply via email to