Database Reference
In-Depth Information
Unfortunately, xmldb:encode-uri does not check for the optional
xmldb:exist:// database prefix (see “XMLDB URIs” on page 92 ) and
erroneously encodes xmldb:exist:///a/b/c into xmldb%3Aexist
%3A/a/b/c , which is probably not what you want.
Relative versus absolute paths
Using relative paths in eXist can be confusing. To help clarify when to use relative
versus absolute paths, we have to distinguish between two situations:
Paths in a static context
These are paths resolved at compile time—for instance, an XQuery import mod
ule at clause, or an xsl:include or xsl:import in an XSLT stylesheet. These
paths are resolved, as expected, against the location of the code that does the
import or include. We strongly advise using relative paths here because it makes
moving your code around much easier.
Paths in a dynamic context
These are paths resolved at run time—for instance, in code like doc("/db/myapp/
data/data.xml") . These paths are resolved using what is called the base collec‐
tion of a query. How this base collection is determined unfortunately depends on
the way the query came to life. The rules are difficult to remember, confusing,
and subject to change as eXist evolves over time.
Because the invocation of a query matters, a relative path is not guaranteed to
always work the same way. So, our advice is to use absolute paths for addressing
collections and resources in code whenever possible.
XMLDB URIs
Instead of writing a direct path to a database resource, such as /db/mycollection/
test.xml , you can use a so-called XMLDB URI . For this, add the prefix xmldb:exist://
in front of the resource, as in xmldb:exist:///db/mycollection/test.xml . (Note that there
are now three slashes after xmldb:exist: .) Used like this, both notations are equivalent
and point to the same document. It's a matter of preference which one to use: the
XMLDB URI is somewhat longer but more specific, and therefore you might con‐
sider it more self-documenting. It is worth noting that when using the Java Admin
Client to execute queries in embedded mode, you have to use the XMLDB URI. Like‐
wise, when writing XQuery using oXygen with eXist, depending on the version, you
may also need to use the XMLDB URI for eXist to recognize module import sources.
Search WWH ::




Custom Search