Your continued donations keep Wikipedia running!    

E4X

From Wikipedia, the free encyclopedia

Jump to: navigation, search

ECMAScript for XML (E4X) is a programming language extension that adds native XML support to ECMAScript (JavaScript). 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 changed that. It treats XML as a primitive (equivalent to a character, integer, or boolean). This implies faster access, better support, and acceptance as a building block (data structure) of a program.

E4X is standardized by Ecma International in ECMA-357 standard. The first edition was published in June 2004, the second edition in December 2005.

var sales=<sales vendor='John'>
  <item id="carrot" price="3" quantity="10"/>
  <item id="chips" price="5" quantity="3"/>
 </sales>
 
for (var i in sales.item) 
 if (sales.item[i].@id == 'carrot') {
  alert(sales.item[i].@quantity); break; 
 }
 
alert(sales.@vendor);


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 tag (ex. <script type="text/javascript; e4x=1">)

Macromedia's ActionScript 3 scripting language fully supports E4X. ActionScript 3 has been available since late 2005.

Resources

Retrieved from "