ECMAScript for XML

ECMAScript for XML

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.

18+
© Academic, 2000-2024
Dictionaries export, created on PHP,
Joomla,
Drupal,
WordPress, MODx.

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”