cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Huib Verweij" <h...@streamtec.nl>
Subject Re: Cforms:Binding to specific element and saving
Date Thu, 23 Jun 2005 18:31:38 GMT
Hi Trondal,

If I understand your message correctly, you are trying to get data from an
xmldb, modify it and write it back. If that's correct, read on...

Getting data out of the xmldb is easy. Getting it back in is a little more
complicated. Not much though. But I got the same errormessage as you at one
stage. It took me some time to come up with a solution. It works but there
may be other, more elegant solutions.

As you say, everything goes well until you want to save your XML back to the
database. My solution is this, in the javascript file you call upon a
sitemap component that injects your data into the pipeline using the JXPath
framework. Then you use xupdate to update your xmldb.

In the javascript file:

    // bind the form's data back to the document
    form.save(document);
    // save the DOM-tree back to XML using the JXPath framework
   cocoon.sendPage("edit-success-pipeline", { "dom":document } );


In the sitemap use this to get your xml back into the pipeline:

    <map:match pattern="edit-success-pipeline">
      <map:generate type="jx" src="resources/jx/edit-success-pipeline.jx">
         <map:parameter name="lenient-xpath" value="true"/>
      </map:generate>
      <map:transform src="update-xmldb.xslt"/>
      <map:transform type="xmldb" />
      .....
      <map:serialize type="html"/>
    </map:match>

The crucial component is the .jx file that generates the data as XML and
inserts it into the pipeline. Once the XML is in the pipeline, use
<map:transform src="update-xmldb.xslt"/> to prepare the xupdate queries and
use <map:transform type="xmldb" /> to execute these queries. Here's the .jx
file:

     <page xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">
         <jx:out value="#{dom/*}"/>
    </page>

The update-xmldb.xslt goes like this:

 <xsl:template match="......">
   <x:query type="update" collection="collection" oid="quis">
     <xu:modifications version="1.0">
        <xu:remove select="//courses/courses.xml#/users/user[@id='1']" />
        <xu:insert-before child="1"
select="//quis/courses/courses.xml#/users/*"><xsl:copy-of select="user"
/></xu:insert-before>
     </xu:modifications>
   </x:query>
 </xsl:template>


or something like that, feel free to experiment to get it exactly right ;-).

I'm curious to see if anyone's come up with another solution.

I hope this helps, good luck.

Huib.

----- Original Message ----- 
From: "trondal" <trondal@stud.ntnu.no>
To: <users@cocoon.apache.org>
Sent: Wednesday, June 22, 2005 6:58 AM
Subject: Cforms:Binding to specific element and saving


>
> I want to bind to just <user id="1"> on the following xml-file:
> <users>
> <user id="1">
> <name>Johan</name>
> </user>
> <user id="2">
> <name>Mark</name>
> </user>
> </user>
>
> Here are the sitemap whitch does the job:
>
> <map:match pattern="modify_course">
>        <map:call function="handleForm">
>          <map:parameter name="function" value="{0}"/>
>          <map:parameter name="form-definition"
> value="modify_course_definition.xml"/>
>          <map:parameter name="documentURI"
> value="xmldb:exist:///quis/courses/courses.xml#/users/user[@id='1']"/>
>    <map:parameter name="bindingURI"
> value="modify_course_binding.xml"/>
>     </map:call>
> </map:match>
>
> All works well until i save: "Cannot modify a resource that includes an
> XPATH expression".
> Previos samples-examples with bindings have worked well, but they all work
> on a easily identifiable path.
> How can I use Xpath to identify the element, and still save the modified
> part?



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message