Database Reference
In-Depth Information
Create or update
If a document with the same URI does not yet exist in the database, it will be cre‐
ated. However, if a document with the same URI is already present, it will be
overwritten with the new instance content.
The major disadvantage of this approach is that we can only create a single document
in the database, when it's likely we'll want many users to fill out our form and the
results to be stored into the database and/or further processed. Solving this will be
discussed next.
Submission via XQuery
You have seen how you may store the result of an XForm directly into eXist via the
REST Server without having to know anything more than XForms. However, this
approach is quite limited, so we will now look at submission via XQuery to dynami‐
cally store and/or post-process the instance content.
By submitting the instance content to a stored XQuery via the REST Server, we have
the full power of XQuery at our fingertips to help us decide how to then store the
document into the database. Of course, we may also do some post-processing and
assert some control over the result of the XForms submission by having the XQuery
return an appropriate HTTP response to the submission. Now we will look at storing
each instance submission into its own document in the database collec‐
tion /db/registration .
Say you create the collection /db/registration , and then store the XQuery shown in
Example 10-5 into the database at /db/registration.xq .
Example 10-5. Submission via stored query
xquery version "1.0" ;
import module namespace request = "http://exist-db.org/xquery/request" ;
import module namespace xmldb = "http://exist-db.org/xquery/xmldb" ;
let $ doc-db-uri := xmldb:store
( "/db/registration" ,
(),
request:get-data () )
return
<stored>
<dbUri> { $ doc-db-uri } </dbUri>
< uri > http : //{ request:get-server-name ()} : { request:get-server-port ()}
{ request:get-context-path ()}/ rest { $ doc-db-uri } < / uri >
< / stored>
The XQuery function xmldb:store will store a document into a database collec‐
tion in eXist.
Search WWH ::




Custom Search