Database Reference
In-Depth Information
list of all resources can be quite useful in some cases—for instance, for showing the
user a list of available content.
You can also use functions from the xmldb extension module for
iterating over the contents of collections. Read more about this in
“Controlling the Database from Code” on page 107 .
You can easily check whether a node points to an XML document by calling
exists($doc/*) , where $doc is a member of a sequence returned by collection as
in the preceding example. This will only return true for XML documents.
Remember, the behavior of the collection function is
implementation-defined. This means that your XQuery's calls to
fn:collection may not behave the same on different platforms,
which can introduce issues for code portability.
The doc Function
If you know (or have computed) the URI to an XML document, the easiest and most
straightforward way to address its content is using the XPath doc function. For exam‐
ple:
let $ documenturi := "/db/myapp/contents.xml"
for $ item in doc ( $ documenturi )// Item
return .. .
An interesting (and sometimes useful) behavior of the doc function in eXist is that
when it gets passed the URI of a nonexistent or non-XML document, it silently
returns the empty sequence (without throwing an error).
Querying the Database Using REST
The simplest and most often used way to access the database's content is using eXist's
REST (a.k.a. REST-style or RESTful) interface. It allows you to query the database by
firing HTTP requests at it. You can do this programmatically from another applica‐
tion or, for GET requests, by hand using a web browser. This section will examine
eXist's REST interface at a fairly basic level; a more thorough explanation (from a sys‐
tem integration point of view) can be found in “REST Server API” on page 319 .
By default, to access the REST interface for a standard eXist setup, start the URLs
with:
http://localhost:8080/exist/rest/
Search WWH ::




Custom Search