Database Reference
In-Depth Information
Querying the database
There are two approaches for sending XQueries to the REST Server API to be exe‐
cuted against the database: HTTP GET and HTTP POST . Both approaches offer very
similar functionality and results; however:
• HTTP GET is most suitable for small and short XQuery or XPath expressions.
You may send these expressions in the query part of the URL using the _query
parameter. The path part of the URI indicates the context upon which to query
the database (i.e., a collection or document), unless the context is set manually in
XQuery through the fn:doc or fn:collection functions.
• HTTP POST is suitable for XQuery main modules. You may send the main mod‐
ule inside an XML document that describes the query in the body of the request.
Imagine that you have a collection of XML documents ( /db/people ) in eXist that con‐
tain details about people. Each document in the collection represents a single person,
and among other things contains that person's name and date of birth (see
Example 13-4 ).
Example 13-4. XML document for a person
<?xml version="1.0" encoding="UTF-8"?>
<person>
<name>
<first-name> John </first-name>
<family-name> Smith </family-name>
</name>
<born>
<date> 1974-05-16 </date>
<location>
<settlement> Tiverton </settlement>
<country> United Kingdom </country>
</location>
</born>
<residence>
<location>
<address-line> 123 High Street </address-line>
<settlement> Cullompton </settlement>
<county> Devon </county>
<country> United Kindom </country>
</location>
</residence>
<contact>
<telephone type= "mobile" > +44 7777 123456 </telephone>
<email> john.smith@johnsmith.com </email>
</contact>
</person>
Search WWH ::




Custom Search