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