antun
08-20-2003, 11:34 AM
A common workflow in Laszlo applications is to manually tweak an XML document on the client and send it to the server that's expecting it, or have it affect replicated views.
First you need a dataset (myds in the example below). myds is empty for simplicity, but you could always use a dataset with existing data already in it, and manipulate or add to that.
To be able to add or manipulate to the data you need a datapointer to a node in the dataset, then you can call the addNode() method:
http://www.laszlosystems.com/developers/learn/documentation/lzxref/datapointer.php#meth-addNode
Here's the example:
<canvas debug="true">
<debug x="150" height="300" />
<dataset name="myds">
</dataset>
<button>Make XML
<method event="onclick">
// Obtain a datapointer
var dp = canvas.datasets.myds.getPointer();
// Create a root node
var newNodeName = 'myrootnode';
dp.addNode( newNodeName );
// Move the pointer to the newly created root node
dp.setXPath( newNodeName );
// Create three child nodes
newNodeName = 'foo';
dp.addNode( newNodeName, 'One', {bar : "1"} );
dp.addNode( newNodeName, 'Two', {bar : "2"} );
dp.addNode( newNodeName, 'Three', {bar : "3"} );
// Write out the contents of the dataset for debugging
var dspointer = canvas.datasets.myds.getPointer();
debug.write( dspointer.serialize() );
</method>
</button>
</canvas>
First we created a root node, then moved the pointer into it, and created three nodes inside:
<myrootnode>
<foo bar="1">One</foo>
<foo bar="2">Two</foo>
<foo bar="3">Three</foo>
</myrootnode>
Enjoy!
First you need a dataset (myds in the example below). myds is empty for simplicity, but you could always use a dataset with existing data already in it, and manipulate or add to that.
To be able to add or manipulate to the data you need a datapointer to a node in the dataset, then you can call the addNode() method:
http://www.laszlosystems.com/developers/learn/documentation/lzxref/datapointer.php#meth-addNode
Here's the example:
<canvas debug="true">
<debug x="150" height="300" />
<dataset name="myds">
</dataset>
<button>Make XML
<method event="onclick">
// Obtain a datapointer
var dp = canvas.datasets.myds.getPointer();
// Create a root node
var newNodeName = 'myrootnode';
dp.addNode( newNodeName );
// Move the pointer to the newly created root node
dp.setXPath( newNodeName );
// Create three child nodes
newNodeName = 'foo';
dp.addNode( newNodeName, 'One', {bar : "1"} );
dp.addNode( newNodeName, 'Two', {bar : "2"} );
dp.addNode( newNodeName, 'Three', {bar : "3"} );
// Write out the contents of the dataset for debugging
var dspointer = canvas.datasets.myds.getPointer();
debug.write( dspointer.serialize() );
</method>
</button>
</canvas>
First we created a root node, then moved the pointer into it, and created three nodes inside:
<myrootnode>
<foo bar="1">One</foo>
<foo bar="2">Two</foo>
<foo bar="3">Three</foo>
</myrootnode>
Enjoy!