Posted by
HankRatz on
URL: https://discuss.orbeon.com/Querying-an-XML-database-eXist-db-tp1459077p1459131.html
Markku,
[reply within]
On Feb 1, 2010, at 10:01 AM, .::: Markku :::. wrote:
> Hi,
>
>
> I would like to execute an XQuery expression against data stored in eXist-db. I know that there are a couple of different approaches for doing that so I thought, hey, let's try them all in order to compare the different approaches.
>
> First, I decided to try out eXist-db's REST API. The following code on my XHTML+XForms Web page worked fine (eXist-db is running as a separate Web application):
> ------------- 8< -------------
> ...
> <xforms:model>
> <xforms:instance id="courses-instance">
> <dummy xmlns="" />
> </xforms:instance>
> <xforms:submission id="select-courses-submission" serialization="none" method="get" resource="
http://localhost:8080/exist/rest/db/courses/courses.xml?_query=//courses&_wrap=no" replace="instance" instance="courses-instance" />
> <xforms:send submission="select-courses-submission" ev:event="xforms-ready" />
> </xforms:model>
> ...
> --------------- 8< -------------
Can a send element be a child of a model? I assumed no. I thought this kind of
initialization requires a xforms-model-construct or xforms-ready event.
At this point, I may be no help at all to you, sorry, but I have never had a
problem getting any control to redraw when any instance referenced changes. I mostly
have not needed XPL when querying eXist.
<xforms:instance id="query">
<config xmlns="">
<_query/>
<_start>1</_start>
<_howmany>0</_howmany>
<_cache>yes</_cache>
<_session/>
</config>
</xforms:instance>
<xforms:bind nodeset="instance('query')">
<xforms:bind nodeset="_query"
calculate="concat('collection(''/dbroot'')/somethings/something',
'[element1=''', instance('qform')/element1, ''']',
'[time >= ''', instance('qform')/start-date, ''']',
'[time <= ''', instance('qform')/end-date, ''']')"/>
<xforms:bind nodeset="_start" constraint=". > 0" />
<xforms:bind nodeset="_howmany" />
<xforms:bind nodeset="_cache" />
<xforms:bind nodeset="_session" relevant=". != ''" />
</xforms:bind>
<!-- Submits the query instance to a service that packages it -->
<xforms:submission id="query-sub"
ref="instance('query')"
method="get"
action="
http://db.nees.ucsb.edu/exist/rest"
separator="&"
validate="false"
replace="instance"
instance="qresult" />
The _query bind can get complicated. POST looks quite different, but even GET
will allow you to construct something like:
<xforms:bind nodeset="_query"
calculate="concat('for $element in collection(''/'')//something',
'[sub-elemement=', instance('qform')/element, ']',
' order by substring($element/sub-element,5)',
' return $element' )"/>
and sort the output.
Well, I'm sure I havent' answered your question, but I think you needed the
call-xpl because the send is not automatic on model construct. So, I'm
suggesting that you have a way to construct automatically the query and
then trigger it at xforms-model-construct and other times.
Regards,
Hank
>
>
> Next, I wanted to try out Orbeon Forms' XForms Submission Processor. I modified my page-flow.xml a bit, which looked like this after the modifications:
> <?xml version="1.0" encoding="UTF-8"?>
> <config xmlns="
http://www.orbeon.com/oxf/controller">
> <page path-info="/my-app/" view="view2.xhtml"/>
> <page path-info="/my-app/selectcourses" model="select_courses.xpl" />
> <epilogue url="oxf:/config/epilogue.xpl"/>
> </config>
>
> And added the select_courses.xpl file:
> <?xml version="1.0" encoding="utf-8"?>
> <p:config xmlns:p="
http://www.orbeon.com/oxf/pipeline"
> xmlns:oxf="
http://www.orbeon.com/oxf/processors"
> xmlns:xforms="
http://www.w3.org/2002/xforms"
> xmlns:xxforms="
http://orbeon.org/oxf/xml/xforms">
> <p:param name="data" type="output" />
> <p:processor name="oxf:xforms-submission">
> <p:input name="submission">
> <xforms:submission method="get" action="
http://localhost:8080/exist/rest/db/courses/courses.xml?_query=//courses&_wrap=no" xxforms:username="guest" xxforms:password="guest" />
> </p:input>
> <p:input name="request">
> <parameters/>
> </p:input>
> <p:output name="response" ref="data" />
> </p:processor>
>
> </p:config>
>
> Here is a code snippet from view2.xhtml:
> ------- 8< ------------
> ...
> <xforms:model>
> <xforms:instance id="courses-instance">
> <dummy xmlns="" />
> </xforms:instance>
> <xforms:insert nodeset="instance( 'courses-instance' )" origin="xxforms:call-xpl( 'oxf:/apps/my-app/select_courses.xpl', 'data', instance( 'courses-instance' ), 'data' )" ev:event="xforms-ready" />
> </xforms:model>
> ...
> ------------- 8< -------------
>
> The aforementioned example works fine and I am able to retrieve the data from the database.
>
>
> Then, I tried to do the same but without using the call-xpl() solution. I never managed to make it work :( Could somebody help me out with this one, and provide me a working solution (XHTML+XForms code + XPL code) with explanations?!?
>
> I would also like to know what changes I need to make in order to use the approach described here:
>
http://www.orbeon.com/orbeon/doc/processors-xmldb#xmldb>
> Kind regards
>
>
> -Markku
>
> --
> You receive this message as a subscriber of the
[hidden email] mailing list.
> To unsubscribe: mailto:
[hidden email]
> For general help: mailto:
[hidden email]?subject=help
> OW2 mailing lists service home page:
http://www.ow2.org/wwsHank Ratzesberger
NEES@UCSB
Institute for Crustal Studies,
University of California, Santa Barbara
805-893-8042
--
You receive this message as a subscriber of the
[hidden email] mailing list.
To unsubscribe: mailto:
[hidden email]
For general help: mailto:
[hidden email]?subject=help
OW2 mailing lists service home page:
http://www.ow2.org/wws