Saturday, February 17, 2007

Removing nodes from an XML document in Flex 2

E4X is the ECMAScript language extension for accessing and manipulating XML. One odd thing about E4X is that it has no methods for removing nodes. This has stumped me for a while, but I just discovered that you simply use the delete operator:

var doc:XML = <folder label="Parent" name="parent">
   <folder label="Child A" name="childa"/>
   <folder label="Child B" name="childb"/>
 </folder>;

// remove the child folders
delete doc.folder;

trace(doc.toXMLString());

Easy once you know how to do it.

No comments: