ECMAScript for XML (E4X) is a programming language extension that adds native XML support to ECMAScript (which includes ActionScript, DMDScript, JavaScript, JScript). 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 [http://www.ecma-international.org/publications/standards/Ecma-357.htm ECMA-357 standard] . The first edition was published in June 2004, the second edition in December 2005.
Example
var sales = ;
alert( sales.item.(@type = "carrot").@quantity ); alert( sales.@vendor ); for each( var price in sales..@price ) { alert( price ); }
Implementations
The first implementation of E4X was designed by Terry Lucas and John Schneider and appeared in BEA's Weblogic Workshop 7.0 released in February 2002. BEA's implementation was based on Rhino and released before the ECMAScript E4X spec was completed in June 2004. John Schneider wrote an [http://dev2dev.bea.com/pub/a/2002/09/JSchneider_XML.html article] on the XML extensions in BEA's Workshop at the time. The reference documentation for this pre-E4X language is [http://e-docs.bea.com/workshop/docs70/help/guide/xmlmap/conHandlingXMLWithECMAScriptExtensions.html still available] .
E4X is implemented in SpiderMonkey (Gecko's JavaScript engine) and in Rhino (Mozilla's other JavaScript engine written in Java instead of C).
As Mozilla Firefox is based on Gecko, it can be used to run scripts using E4X. The specification is supported in the 1.5 release or later.
Note: To correctly run a script using Firefox 1.5 "; e4x=1" must be appended to the end of the script "type" attribute (e.g. ).
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.
E4X is available in Flash CS3, Adobe AIR and Adobe Flex as they use ActionScript 3 as a scripting language.
E4X is also available in Adobe Acrobat and Adobe Reader versions 8.0 or higher.
E4X is also avilable in Aptana's Jaxer Ajax application server which uses the Mozilla engine server-side.
Since the release of Alfresco Community Edition 2.9B, E4X is also available in this enterprise document management system.
Criticisms
Most e4x implementations don't have a means to import and export DOM nodes to/from the e4x model.
Alternatives
JSON
In the absence of E4X support, it is possible to use JSON instead of XML. JSON is an object-oriented data notation similar to XML. JSON is part of the ECMAScript (JavaScript) standard and works with all standard JavaScript engines. JSON has less powerful querying capabilities than E4X because the objects stored have a single index instead of multiple indices, as E4X does.
The above example would look like this with JSON and non-E4X dependent JavaScript: var sales = { "vendor" : "John", "items" : [ { "type" : "peas", "price" : "4", "quantity" : "6" }, { "type" : "carrot", "price" : "3", "quantity" : "10" }, { "type" : "chips", "price" : "5", "quantity" : "3"} ] };
for( var i in sales.items) { if (sales.items [i] .type="carrot") alert( sales.items [i] .quantity ); } alert( sales.vendor ); for( var i in sales.items ) { alert( sales.items [i] .price ); }
Resources
* [http://www.ecma-international.org/publications/standards/Ecma-357.htm ECMA-357 standard] * [http://www.faqts.com/knowledge_base/index.phtml/fid/1762 E4X at faqts.com] * [http://developer.mozilla.org/presentations/xtech2005/e4x/ Slides from 2005 E4X Presentation by Brendan Eich, Mozilla Chief Architect] * [http://developer.mozilla.org/en/docs/E4X E4X at Mozilla Developer Center] * [http://www.xml.com/pub/a/2007/11/28/introducing-e4x.html Introducing E4X at xml.com] : compares E4X and json * [http://developer.mozilla.org/index.php?title=En/Core_JavaScript_1.5_Guide/Processing_XML_with_E4X Processing XML with E4X] at Mozilla Developer Center * [http://www.w3schools.com/e4x/default.asp Tutorial from W3 Schools] * [http://developer.yahoo.com/flash/articles/e4x-beginner-to-advanced.html E4X: Beginner to Advanced] at Yahoo Developer Network
ECMAScript for XML — (kurz: E4X) ist eine standardisierte Programmiersprachenerweiterung für JavaScript und ähnliche Sprachen, die dem ECMAScript Standard folgen. Die Erweiterung macht es möglich, reguläre XML und HTML Elemente als nativen Teil der Programmiersprache … Deutsch Wikipedia
ECMAScript для XML — (E4X) расширение языка программирования, добавляющее естественную поддержку XML в стандарт языка ECMAScript. Цель обеспечить альтернативу DOM интерфейсам для упрощения синтаксиса для доступа к XML документам. Также предлагается новый… … Википедия
ECMAScript — est un langage de programmation de type script standardisé par Ecma International dans le cadre de la spécification ECMA 262. Il s agit donc d un standard dont les spécifications sont mises en œuvre dans différents langages script, comme… … Wikipédia en Français
Ecmascript — est un langage de programmation de type script standardisé par Ecma International dans le cadre de la spécification ECMA 262. Il s agit donc d un standard dont les spécifications sont implémentées dans la plupart des langages script, comme… … Wikipédia en Français
ECMAScript — Infobox programming language name = ECMAScript paradigm = Multi paradigm: prototype oriented, functional, imperative, scripting year = 1997 designer = Brendan Eich, Ecma International turing complete = Yes typing = duck, weak, dynamic… … Wikipedia
ECMAScript — JavaScript ist eine Skriptsprache, die hauptsächlich für das DOM Scripting in Web Browsern eingesetzt wird. Dabei ist unter JavaScript die Gesamtheit aus den Eigenschaften des Browsers (beziehungsweise Clients oder Scripting Hosts) sowie des… … Deutsch Wikipedia
XML — Infobox file format name = Extensible Markup Language icon = logo = extension = .xml mime = application/xml, text/xml (deprecated) type code = uniform type = public.xml magic = owner = World Wide Web Consortium genre = Markup language container… … Wikipedia
XML Events — is a W3C specification for handling events occurring in an XML document. These events are typically caused by a user interacting with the document as a web page using a device such as a web browser on a PC, mobile phone or telephone. Formal… … Wikipedia