HOW TO: Delete an XML node using E4X
While creating a sample application for some class content the other day, I ran into an XML/E4X situation that I'd never encountered before. It is pretty basic - deleting a node from XML. How does one do it? With the delete keyword of course!
For example:
Actionscript:
-
var myXML:XML =
-
<order>
-
<item id="0" name="main">Hamburger</item>
-
<item id="1" name="side">Fries</item>
-
<item id="2" name="drink">Med. Soda</item>
-
<item id="3" name="drink">Lg. Soda</item>
-
</order>;
-
-
// Delete the Med. Soda node
-
-
// Output the XML
-
trace( myXML.toXMLString() );
-
-
// Result
-
//<order>
-
// <item id="0" name="main">Hamburger</item>
-
// <item id="1" name="side">Fries</item>
-
// <item id="2" name="drink">Med. Soda</item>
-
// <item id="3" name="drink">Lg. Soda</item>
-
//</order>
-
-
delete myXML.item[2];
-
-
// Output the edited XML
-
trace( myXML.toXMLString() );
-
-
// Result
-
//<order>
-
// <item id="0" name="main">Hamburger</item>
-
// <item id="1" name="side">Fries</item>
-
// <item id="3" name="drink">Lg. Soda</item>
-
//</order>
Man, E4X is so simple!
|
|
download: Delete Node Example (4.78KB) added: 04/09/2009 clicks: 72 description: Code source (.FLA) for delete XML node using E4X in ActionScript 3 sample |












noo, really ?? -_-
Yeah really. The post might be helpful to someone - unlike your comment. -_-