cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gianluca Morello" <more...@S1.my-tv.it>
Subject Re: Woody binding on XML subtree
Date Fri, 16 Jan 2004 11:50:16 GMT
Hi,


my approach is:

create a document fragment from the original document and bind it to the
woody form.
after form submission reappend the fragment to the original document and
save it.

this is my code:

try to adapt to your xml files, i'm using the position of the element i want
to edit  but you can use also an unique attribute.

function form2xml() {
     var pos = cocoon.request.getParameter("pos");
     document=loadDocument(documentURI);
     var nl =
document.getFirstChild().getChildNodes().item(1).getChildNodes();
     for ( i = 0; i < nl.getLength (); i++) {
            var cur_node=nl.item(i);
            if (cur_node.getNodeType()==1) {
                   counter++;
                   if (counter==pos) {
                         var newdoc=document.createDocumentFragment();
                         newdoc.appendChild(cur_node);
                         form.load(newdoc);
                        form.show("display-edit", formHandler);
                        form.save(newdoc);
                       nl.item(1).getParentNode().appendChild(
newdoc.getFirstChild());
                       saveDocument(document, documentURI);
                        return;
                    }
            }
    }
}


Hope this help.


----- Original Message -----
From: "Kamal Dalal" <kamal@banoora.net>
To: <users@cocoon.apache.org>
Sent: Friday, January 16, 2004 10:41 AM
Subject: Re: Woody binding on XML subtree


> On Mon, 20 Oct 2003 09:59:19 -0500, jcplerm wrote:
>
> > Is there a way of having a Woody form being populated through the
binding
> > framework in a way that the form involves just a subtree of the original
> > XML doc?
> >
> > For instance, given the following complete XML doc:
> >
> > <root>
> >     <elem id="100">
> >         <name>name100</name>
> >         <address>address100</address>
> >     </elem>
> >     <elem id="101">
> >         <name>name101</name>
> >         <address>address101</address>
> >     </elem>
> >     <elem id="102">
> >         <name>name102</name>
> >         <address>address102</address>
> >     </elem>
> > </root>
> >
> > I would like a form to edit the just the subtree located by
> > "/root/elem[@id='101']".
> >
> > Can the binding definition file somehow be parametrized, or can
something
> > along these lines be done?
>
> It is possible to parametrize the binding file by filtering it through a
> JXTemplateGenerator for example. Here is an outline of the solution :
>
> In your sitemap, pass a form binding uri with value="cocoon:/bind_with"
> The matcher for bind_with generates:
>
>  <map:generate type="jx" src="form_bind.jx">
>                     <map:parameter name="parentpath"
>                     value="elem[@id={myparameter}]"/>
>
> and in your form_bind.jx repeater, you will have :
>
>         parent-path="${parameters.getParameter('parentpath')}"
>
> -Kamal
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>



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


Mime
View raw message