View Full Version : How to clear/empty a node?
AllanJun
11-01-2006, 02:34 PM
I want to clear all the attributes and texts of a node including all the children note. Is there a convenient way to do this?
deleteNode() doesn't work for I need to use the schema of the node later on.
Thx in advance.
jks_pdx
11-21-2006, 08:46 PM
It's not entirely clear to me what you are trying to accomplish, but the following code I wrote does what I think you were asking for.
<canvas debug="true">
<dataset name='sample'>
<result>
<item category='Component' type='Utilites'>These are some components
<child label='Grid'/>
<child label='Button'/>
</item>
<item category='Media' type='Content'/>
</result>
</dataset>
<datapointer name='myPointer' xpath="sample:/result/item[1]"/>
<button text='Do it' onclick='clearDP(canvas.myPointer)'>
<method name='clearDP' args='inDP'>
<![CDATA[
Debug.write(inDP);
// we can clear out the text as follows
inDP.setNodeText('');
// we can remove children as follows
var lCopyDP;
lCopyDP = inDP.dupePointer();
if (lCopyDP.selectChild())
{
while(lCopyDP.p)
{
lCopyDP.deleteNode();
}
}
// we can remove attributes as follows
var lAttr;
for (lAttr in inDP.p.attributes)
{
inDP.p.attributes[lAttr] = '';
}
Debug.write(inDP);
]]>
</method>
</button>
</canvas>
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.