cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bertrand Delacretaz <bdelacre...@apache.org>
Subject Re: Cforms basics
Date Wed, 04 Jan 2006 14:57:05 GMT
Le 4 janv. 06, à 14:46, Peter Flynn a écrit :

> ...Is there an example anywhere of a simple (1-variable) form which
> (a) writes its data to a new XML file and (b) inserts an element
> in an existing file?..

It's not 1-variable, but the XML binding sample (online at  
http://cocoon.zones.apache.org/demos/21branch/samples/blocks/forms/ 
form2xml.flow) shows how to edit an XML file.

The flowscript is at src/blocks/forms/samples/flow/binding_example.js,  
the form2xml() function is what drives the editing process, and defines  
the input and output XML filenames (Sources actually, they can be more  
than filenames).

The corresponding sitemap excerpt (from samples/sitemap.xmap) is:

     <map:match pattern="form2xml.flow">
        <map:call function="handleForm">
          <map:parameter name="function" value="form2xml"/>
          <map:parameter name="definitionURI"  
value="forms/form2_model.xml"/>
          <map:parameter name="documentURI"  
value="forms/form2_data.xml"/>
          <map:parameter name="bindingURI"  
value="forms/form2_bind_xml.xml"/>
        </map:call>
      </map:match>

The form2simpleXML() variant does the same but without using bindings,  
the XML is edited as is, here's the sitemap excerpt:

     <map:match pattern="form2simpleXML.flow">
        <map:call function="handleForm">
          <map:parameter name="function" value="form2simpleXML"/>
          <map:parameter name="definitionURI"  
value="forms/form2_model.xml"/>
          <map:parameter name="documentURI"  
value="forms/form2_simple_data.xml"/>
        </map:call>
      </map:match>

If you need to insert XML at various places in the edited files, the  
binding paths (in the binding definition file) should help, depending  
on how complex the XML manipulation is. For more complex merging of  
data, you can use processPipelineTo from flowscript, to process your  
XML data before writing it to disk.

Hope this helps,

-Bertrand

Mime
View raw message