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:
[as]var myXML:XML =

Hamburger
Fries
Med. Soda
Lg. Soda
;

// Delete the Med. Soda node

// Output the XML
trace( myXML.toXMLString() );

// Result
//
// Hamburger
// Fries
// Med. Soda
// Lg. Soda
//

delete myXML.item[2];

// Output the edited XML
trace( myXML.toXMLString() );

// Result
//
// Hamburger
// Fries
// Lg. Soda
//[/as]
Man, E4X is so simple!
[dm]1[/dm]

Comments
  1. Insane
  2. jccrosby

Leave a Reply

Your email address will not be published. Required fields are marked *