ECMAScript for XML
ECMAScript for XML (E4X) is a programming language extension that adds native XML support to ECMAScript (which includes ActionScript, JavaScript, and 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 ECMA-357 standard. The first edition was published in June 2004, the second edition in December 2005.
Contents |
Browser support
E4X is supported by Mozilla's Rhino, used in OpenOffice.org and several other projects, and SpiderMonkey, used in Firefox, Thunderbird, and other XUL-based applications. It is also supported by Tamarin, the JavaScript engine used in the Flash virtual machine. It is not supported by Nitro (Safari), V8 (Google Chrome), Carakan (Opera), nor Internet Explorer.[1]
As of Firefox 10, E4X syntax is no longer accepted in SpiderMonkey when ECMAStrict 5 "strict mode" is enabled.[2] According to Brendan Eich, "This thus signals start of deprecation for E4X in SpiderMonkey."[3] and as of Firefox 17, E4X will likely be disabled by default[4]
Example
var sales = <sales vendor="John"> <item type="peas" price="4" quantity="6"/> <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 ); } delete sales.item[0]; sales.item += <item type="oranges" price="4"/>; sales.item.(@type == "oranges").@quantity = 4;
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 article on the XML extensions in BEA's Workshop at the time.
- E4X is implemented in SpiderMonkey (Gecko's JavaScript engine) since version 1.6.0[5] and in Rhino (Mozilla's other JavaScript engine written in Java instead of C) since version 1.6R1[6].
- As Mozilla Firefox is based on Gecko, it can be used to run scripts using E4X. But this feature is deprecated since release 16 and removed in release 18.
- 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 available 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.
References
- ^ "Issue 30975: Implement E4X Support for scripts and extensions". Google. http://code.google.com/p/chromium/issues/detail?id=30975. Retrieved 21 May 2012.
- ^ "Firefox 10 for developers". Mozilla. https://developer.mozilla.org/en/Firefox_10_for_developers#JavaScript. Retrieved 21 May 2012.
- ^ "Bug 695577 - E4X syntax should not be accepted in ES5 strict mode". Mozilla. https://bugzilla.mozilla.org/show_bug.cgi?id=695577#c1. Retrieved 21 May 2012.
- ^ "Bug 778851 - Turn javascript.options.xml.content off by default". Mozilla. https://bugzilla.mozilla.org/show_bug.cgi?id=778851. Retrieved 3 September 2012.
- ^ SpiderMonkey 1.6.0 release notes
- ^ Rhino 1.6R1 Change log
External links
- ECMA-357 standard
- E4X at faqts.com
- Slides from 2005 E4X Presentation by Brendan Eich, Mozilla Chief Architect
- E4X at Mozilla Developer Center
- Introducing E4X at xml.com: compares E4X and json
- Processing XML with E4X at Mozilla Developer Center
- Tutorial from W3 Schools
- E4X: Beginner to Advanced at Yahoo Developer Network
- Product showing E4X in action at Script Scraper.
|