Christian, thank you very much - this difference is what I missed, and it is really important.

So - doc() and collection() work in two steps: 

(a) try to interpret the argument URI as a "database resource URI" (defined to be the concatenation of database name and database path), locating a database document or directory

(b) if no database documents were located (that is - the argument is no valid database resource URI): interpret the URI as a file:// URI, locating a file or directory.

Concerning the default collection, I only just now discovered the difference between the function db:open and the command <open name="...">: the command changes the dynamic context for a subsequent query, making the documents of the opened db the default collection - whereas db:open does not change the dynamic context. (Well - otherwise it would not be side-effect free.)

One more question:
Does the open-command change the dynamic context of subsequent queries in any other way except for setting the default collection?

Cheers,
Hans-Juergen



Von: Christian Grün <christian.gruen@gmail.com>
An: Hans-Juergen Rennau <hrennau@yahoo.de>
CC: Base X <basex-talk@mailman.uni-konstanz.de>
Gesendet: 4:07 Samstag, 7.Juli 2012
Betreff: Re: [basex-talk] db:open and collection()

Hi Hans-Jürgen,

> it seems to me that function db:open() and collection() are equivalent.
> [...]

the main difference of the collection() and doc() functions is that
they can also access local resources: you may as well use them to
create a temporary main-memory collection from all files found at the
given local file path [1]. In other words, db:open() will be a little
bit more efficient, and cause no surprises, if you know that your
files are stored in a database.

Hope this helps,
Christian

[1] http://docs.basex.org/wiki/Database#XML_Documents