HOW TO: Delete an XML node using E4X

Written on April 21, 2008 – 11:06 am | by John |

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:
  1. var  myXML:XML =
  2.     <order>
  3.         <item id="0" name="main">Hamburger</item>
  4.         <item id="1" name="side">Fries</item>
  5.         <item id="2" name="drink">Med. Soda</item>
  6.         <item id="3" name="drink">Lg. Soda</item>
  7.     </order>;
  8.  
  9. // Delete the Med. Soda node
  10.  
  11. // Output the XML
  12. trace( myXML.toXMLString() );
  13.  
  14. // Result
  15. //<order>
  16. //  <item id="0" name="main">Hamburger</item>
  17. //  <item id="1" name="side">Fries</item>
  18. //  <item id="2" name="drink">Med. Soda</item>
  19. //  <item id="3" name="drink">Lg. Soda</item>
  20. //</order>
  21.  
  22. delete myXML.item[2];
  23.  
  24. // Output the edited XML
  25. trace( myXML.toXMLString() );
  26.  
  27. // Result
  28. //<order>
  29. //  <item id="0" name="main">Hamburger</item>
  30. //  <item id="1" name="side">Fries</item>
  31. //  <item id="3" name="drink">Lg. Soda</item>
  32. //</order>

Man, E4X is so simple!

http://john.realeyes.com/wp-content/plugins/downloads-manager/img/icons/winzip.gif 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

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Netvouz
  • description
  • ThisNext
  • MisterWong
  • Wists
  • Facebook
  • StumbleUpon
  • Technorati
  • YahooMyWeb

Related Posts

Put your related posts code here
discussion by DISQUS
Add New Comment
Viewing 2 comments — Sort by:
Find entries :

Want to subscribe?

  Subscribe in a reader or,
Subscribe via email:

About me

I'm a senior developer at RealEyes Media, Adobe Certified Instructor and Adobe Certified Professional. Here you'll get my ideas and experience Flex, Flash, ColdFusion and related technologies as well as some generally off the wall stuff.