Database Reference
In-Depth Information
It is also possible to dynamically calculate the URI from which to
retrieve instance data. Unfortunately, this cannot be done through
the
xf:instance
directly, as XPath expressions are not allowed in
the
src
attribute. However, this is possible through clever use of an
xf:submission
and event handling to replace instance content, as
described at
https://en.wikibooks.org/wiki/XForms/
XForms Submissions
Typically, you will want to store the completed result of your XForm somewhere,
either for posterity or for further processing. The responsibility of an
xf:submission
is typically to submit an
instance
from the
model
using a
method
to a
resource
. Almost
all XForms implementations support submission by HTTP
GET
,
POST
, and
PUT
, which
is a great fit for use with eXist's REST Server or RESTXQ APIs. Given that, you can
easily have the result of your completed XForm stored into the database.
Submission to the REST Server
It is relatively trivial to design your XForm to store its result into an XML document
in the eXist database, by simply modifying its
xf:submission
to HTTP
PUT
the
instance into an XML document in a collection within the eXist database.
For example, the
xf:submission
shown in
Example 10-4
, when fired, would place the
result of the XForm into the document
/db/registration/result.xml
within eXist.
Example 10-4. XForms submission to REST Server
<xf:submission
id=
"s-save"
method=
"put"
resource=
"http://localhost:8080/exist/rest/db/registration/result.xml"
replace=
"none"
>
<xf:action
ev:event=
"xforms-submit-error"
>
<xf:message>
Registration failed. Please fill in valid values.
</xf:message>
</xf:action>
<xf:action
ev:event=
"xforms-submit-done"
>
<xf:message>
You have been registered successfully.
</xf:message>
</xf:action>
</xf:submission>
Some advantages of this approach are:
Automatic collection creation
As we are doing an HTTP
PUT
to the REST Server, eXist will create any collecā
tions that do not yet exist but are required to store the document.
Search WWH ::
Custom Search