Database Reference
In-Depth Information
Accessing files
If you want to access a file on the filesystem (not in the database), use the file:// prefix,
as in:
doc ( "file:///home/erik/test.xml" )
To manipulate the filesystem, eXist has a file extension module.
In contrast to what you might expect, this module does not use the
file:// prefix syntax.
The XPath Collection and Doc Functions in eXist
The XPath collection function is defined as returning a sequence of (usually docu‐
ment) nodes. The doc function is defined as returning document-node , or the empty
sequence if it cannot find the document indicated by the passed URI. Both use a URI
as a parameter. These are important functions for XML databases because they allow
you to easily address subsets of your database content for further inspection or pro‐
cessing. The XPath standard defines their behavior as implementation-dependent, so
we need to know how eXist handles them.
The collection Function
The collection function in eXist returns the set of resources residing in the collec‐
tion identified by its URI parameter, including those in its subcollections, recursively.
In other words, it will return a sequence containing all resources underneath a certain
collection path in the database. If you want only the resources in the collection itself
(without those in subcollections) you can use the extension function xmldb:xcollec
tion instead.
Now, maybe to your surprise, collection returns not only the XML documents
found, but all resources. To illustrate this, assume we have a collection called /db/test
in which there are two files: test.xml (an XML file) and test.pdf (a PDF file). Now run
the following query:
for $ doc in collection ( "/db/test" )
return
base-uri ( $ doc )
The result will be /db/test/test.xml and /db/test/test.pdf .
Of course, besides getting their URIs with the base-uri function, you won't be able
to do much with the non-XML nodes returned by collection . However, getting a
Search WWH ::




Custom Search