tags:

views:

36

answers:

2

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?

+1  A: 

The following query might help you:

for $doc in collection('your-db-name')
let $path := base-uri($doc)
where ends-with($path, 'normal.xml')
return $doc/name
Christian
A: 

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.

Ryan Lewis