Database Reference
In-Depth Information
An XForms instance declaration to retrieve this instance would then look like
Example 10-2 .
Example 10-2. Instance retrieval by query submission
<xf:instance xmlns= ""
src= "http://localhost:8080/exist/rest/db/weather?_query=%2Fweather%5B%40date%20eq
%20current-date()%5D&_wrap=no" />
In the URL used in the xf:instance/@src we need to URL-encode
the query string parameter for the XQuery used to ensure that it is
correctly transmitted. We have also added the parameter wrap=no ,
as we want the matched XML document for our instance; other‐
wise, by default it would have been wrapped in an exist:result
element by the REST Server!
See “Querying the database” on page 326 for further information on submitting an
XQuery to the REST Server.
Our next example is a reworking of Example 10-2 , but rather than sending the
XQuery to the database, it instead relies on the fact that we have already stored the
XQuery into the database. Doing so allows us to later invoke the query from the
REST Server by URI and have it executed.
So, if you were to store the following XQuery into the database at /db/weather.xq :
xquery version "1.0";
collection("/db/weather")/weather[@date eq current-date()]
An XForms instance declaration to retrieve this instance would then look like
Example 10-3 :
Example 10-3. Instance retrieval by stored query
<xf:instance xmlns=""
src="http://localhost:8080/exist/rest/db/weather.xq"/>
You have now seen how you can bring in instance data dynamically, but this is really
just scratching the surface of what is possible. You can also send parameters to your
stored XQuery to influence the XML it will produce for your instance. For further
information, see “Executing stored queries” on page 335 and “The request Extension
Module” on page 209 . As an alternative to stored query execution via the REST
Server, you could retrieve an instance from a URI provided by a RESTXQ resource
function; for further details, see “RESTXQ” on page 353 .
Search WWH ::




Custom Search