Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] Re: [NUX] Two step search with XQueryUtil

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Wolfgang Hoschek <whoschek AT lbl.gov>
  • To: Fred Vos <fred AT fredvos.org>
  • Cc: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] Re: [NUX] Two step search with XQueryUtil
  • Date: Mon, 24 Jan 2005 13:22:49 -0800

On Jan 24, 2005, at 1:16 PM, Fred Vos wrote:

Dear Wolfgang,

If you think I should ask this question on th XOM-list, please say so in your
reply and I will post it on that list!

Yes, please ask on the XOM-interest list, so others can also benefit from the exchange and comment.
I'm copying the list here.
More below...


This weekend I started with using NUX. I'm working on an indexing tool for
lucene that can index XML-files using a config-file. The config-file (XML)
describes paths to records, for instance '/tracks/file'. Furthermore it
describes paths to each field of the record, for instance 'comments/artist' or
'comments/album'.

With NUX's XQueryUtil it is easy to get all records from a document:

Nodes nodes = XQueryUtil.xquery(dataDoc, dataSourceRecordPath);
for (int j=0; j < nodes.size(); j++) {
// process each record
}

String variable 'dataSourceRecordPath' contains the path to each record, like
'/tracks/file' in the example above.

But it is more difficult to get each field from the record, because all I have
is nodes, not elements. How can I get the value of the 'comments/artist'
element for a certain record node?

I did find a stupid solution: I convert each node with the toXML() method into
a string and parse this string into a new document and then use XQueryUtil
again to fetch the field values.

I cannot believe this is the best way to achieve the results I want. Do you
have a better suggestion?

Thanks in advance for your answer and for your work on NUX.

Fred

You could try another query on the results of the first query, something along the following lines:

Nodes nodes = XQueryUtil.xquery(dataDoc, dataSourceRecordPath);
for (int j=0; j < nodes.size(); j++) {
// process each record
Nodes subNodes = XQueryUtil.xquery(nodes.get(j), "comments/artist");
for (int i=0; i < subNodes.size(); i++) {
// process each subrecord
}
}

Wolfgang.




  • [XOM-interest] Re: [NUX] Two step search with XQueryUtil, Wolfgang Hoschek, 01/24/2005

Archive powered by MHonArc 2.6.24.

Top of Page