PDA

View Full Version : to add node from datapointer


epopov
02-09-2004, 08:44 AM
Hi,
I have some XML data in my application. For example:

<mynode>
<sub1 id="1" />
<sub1 id="2" />
<sub1 id="3" />
</mynode>

And I want to add <sub1 id="4" /> node, and I want result XML became as follows:
<mynode>
<sub1 id="4" />
<sub1 id="1" />
<sub1 id="2" />
<sub1 id="3" />
</mynode>

Is it possible? Is there some API that can do this?

antun
02-09-2004, 11:41 AM
Once you've got a datapointer in there, you can then call all the datapointer methods for adding/deleting/copying/moving nodes:


<canvas debug="true">

<dataset name="myds">
<mynode>
<sub1 id="1" />
<sub1 id="2" />
<sub1 id="3" />
</mynode>
</dataset>

<simplelayout axis="y" spacing="10" />

<button>Add new node - old method
<method event="onclick">
var dp = canvas.datasets.myds.getPointer();
dp.selectChild();
dp.addNode( "sub1", null, {id: 4} )
canvas.serializeDP( dp );
</method>
</button>

<button>Serialize entire dataset
<method event="onclick">
canvas.serializeDP( canvas.datasets.myds.getPointer() )
</method>
</button>

<method name="serializeDP" args="dp">
Debug.write( dp.serialize() );
</method>

</canvas>


-Antun