I may be doing this completely wrong to begin with, so try not to be too shocked at my examples! ;c)
My BaseX database consists of songs. They were loaded from individual XML files that are stored in a directory structure. I'm searching for songs that contain given lyrics. So far so good. I'm NOT returning XML format data, but tabular data. I'm using the "return" clause with the concat() function of XQuery to formulate each results row. For instance "song title", "author", "lyrics", etc. One row per song that is found from my search.
What I'd like to be able to do is to have that results row also contain the information in the "doc" node so that in addition to selected contents of the XML file, the results row would also contain the file name and the relative directory path (which I see are in the "doc" node when I use the BaseX GUI).
Here's a real-life example of a query that works well for me to return rows of elements found WITHIN the XML file:
for $song in collection("OpenSongSearch")
where $song/song/lyrics[ . contains text "baloche"] or $song/song/title[ . contains text "baloche"] or $song/song/author[ . contains text "baloche"]
order by $song/song/title
return concat($song/song/title,string('|'),$song/song/author,string('|'),replace(re place($song/song/lyrics,'\n','^line^'),'[\w+]',''),string(' '))
The program that invokes the BaseX call parses these results to put into a listbox in a dialog.
The only thing that I knew to try to add the "doc" node was:
return concat($song/doc,string('|'), $song/song/title,string('|'),$song/song/author,string('|'),replace(replace($ song/song/lyrics,'\n','^line^'),'[\w+]',''),string(' '))
This did not give me an error but simply added the additional vertical bar at the beginning and no "doc" node info.
I know this is more of a XQuery question than a BaseX question per se, but any hints for novice would be greatly appreciated.
Thanks!
mailto:david@leighweb.com DavidEmailSig