Hi Sony I think, your need can be easily fulfilled. For example I use following XQuery as sort of "dir" command.
for $doc in collection() return base-uri($doc)
Just do your task the same way, add your where condition and modify the return statement and you are done.
And if you use some API to get the results, there are options to get back particular parts of the response part by part, see http://docs.basex.org/wiki/Language_Bindings and refer to examples 3 and 4:
- QueryExample shows you how to evaluate queries *in an iterative*manner. - QueryBindExample shows you how to bind a variable to your query and evaluates the query *in an iterative manner*.
Good luck
Jan
2011/4/22 Sony Vijay sony.vibh@gmail.com
Hi,
Is there a way to return variable-length results using xquery ?
Consider the following xml file (document name: doc1)
<feed> <title>feed1</title> <entry> <id>1</id> <title>entry 1 title *match*</title> <content>entry 1 content *match* </content> </entry> <entry> <id>2</id> <title>entry 2 title *match*</title> <content>entry 2 content *match* </content> <author> <name>entry 2 author *match* </name> </author> </entry> </feed>
Consider that there are multiple xml files in my database. I am trying to run an xquery which would perform a search across all the xml files in the database which contain entires with the matching key. Then for each matching document, return all the entry nodes with at least one match, followed by a list of nodes with the match.
Say the match key word is: "match", the desired result is the following:
- document name (doc1), id (1), *[**title (entry 1 title match),
content (entry 1 content match)], *document name(doc1), id (2),* [title (entry 2 title match), content (entry 2 content match), author: name (entry 2 author match)]*
Please note that the first entry(id=1) contains two matching nodes whereas the second entry(id=2) contains 3 matching nodes. Returning a variable length result as shown above would help me identify the next matching document name and entry id.
Currently, I perform this action by splitting the task into 2 sub-tasks:
- Return the document name and entry id with at least one match using
one xquery
- Return the list of matching child nodes for each of the above entries
using a second xquery
Is there a better way to do this?
Thanks, Sony
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk