E4X in ActionScript 3
E4X stands for ECMAScript for XML. (ActionScript is an implementation of ECMAScript.)
E4X is a Document Object Model (DOM) interface for XML. E4X makes XML a first-class citizen in ActionScript.
var xmlAlbum:XML = <album name="Sky Blue Sky" artist="Wilco"> <tracks> <track name="Either Way" seconds="187"/> <track name="You Are My Face" seconds="278"/> <track name="Impossible Germany" seconds="358"/> <track name="Sky Blue Sky" seconds="203"/> <track name="Side With The Seeds" seconds="256"/> <track name="Shake It Off" seconds="342"/> <track name="Please Be Patient With Me" seconds="199"/> <track name="Hate It Here" seconds="273"/> <track name="Leave Me (Like You Found Me)" seconds=""/> <track name="Walken" seconds="267"/> <track name="What Light" seconds="216"/> <track name="On And On And On" seconds=""/> </tracks> </album>
Notice in the example that you are not wrapping the XML in quotes or treating it as a string. Just type the XML as a literal.
Of course you can turn a string into XML, and back:
// turn a string into XML var xmlPerson:XML = XML( "<person><firstName>Jeff</firstName><lastName>Tweedy</lastName></person>" ); // turn XML into a string var personStr:String = xmlPerson.toXMLString();
E4X classes in the "Top Level" package:
- XML - methods for an XML element (could be a document)
- XMLList - methods for a list of XML elements
- QName - (see ActionScript documentation for more information)
- Namespace - (see ActionScript documentation for more information)
More
Learn more about working with XML in ActionScript...

