E4X
From Wikipedia, the free encyclopedia
ECMAScript for XML (E4X) is a programming language extension that adds native XML support to ECMAScript (which include ActionScript, DMDScript, JavaScript, JScript). It does this by providing access to the XML document in a form that mimics XML syntax. The goal is to provide an alternative to DOM interfaces that uses a simpler syntax for accessing XML documents. It also offers a new way of making XML visible. Before the release of E4X, XML was always accessed at an object level. E4X instead treats XML as a primitive (like characters, integers, and booleans). This implies faster access, better support, and acceptance as a building block (data structure) of a program.
E4X is standardized by Ecma International in the ECMA-357 standard. The first edition was published in June 2004, the second edition in December 2005.
var sales = <sales vendor="John"> <item type="peas" price="4" quantity="5"/> <item type="carrot" price="3" quantity="10"/> <item type="chips" price="5" quantity="3"/> </sales>; alert( sales.item.(@type == "carrot").@quantity ); alert( sales.@vendor ); for each( var price in sales..@price ) { alert( price ); }
[edit] Implementations
E4X is implemented (at least partially) in SpiderMonkey (Gecko's JavaScript engine) and in Mozilla's other JavaScript engine (written in Java instead of C), Rhino.
As Mozilla Firefox is based on Gecko, it can be used to run scripts using E4X. The specification is relatively new and is only supported in the 1.5 release or later.
Note: To correctly run a script using Firefox 1.5 you must append "; e4x=1" to the end of the script type attribute (eg. <script type="text/javascript; e4x=1">) -- Note Using FireFox 1.5.011 that no longer seems needed http://www.scottwickham.com/e4x/
Adobe's ActionScript 3 scripting language fully supports E4X. Early previews of ActionScript 3 were first made available in late 2005. Adobe officially released the language with Flash Player 9 on June 28, 2006.