If I add two documents to a BaseX DB, let's say normal.xml
and normal2.xml
, is there a way to refer to each one individually?
I know about the doc()
function, but it looks at the filesystem for their location, rather than in the database itself.
For instance, if I query with this: doc("normal.xml")/name
, then I will get an error about normal.xml
not being found.
I also tried: basex:db("my-db-name")/doc("normal.xml")/name
and received the same error.
Any ideas?
I ended up asking on the BaseX mailing list and the answer I received is as follows:
for $doc in collection('test-db')
where matches(document-uri($doc), 'example.xml')
return $doc
I also inquired as to why there was no direct way to reference the document one would want to extract data from in constant time, and the response was:
This is due to the XQuery data model. XQuery has no formal notion of files inside a database/collection (Christian might correct me if I am wrong), so the collection() command returns any sequence of (document-)nodes for the given database. It is up to the user to pick those nodes he wants to process.
We are currently looking for ideas on navigating collections more intuitively; something similar to "collection('db/path-to/document.xml')" that should still conform to the current W3C recommendation. As the subsequent document-uri() usually works well enough this is not too high on our priority list.
Thanks for the help though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With