Section 5.3. ECMAScript for XML (E4X)


5.3. ECMAScript for XML (E4X)

While the ECMAScript standard (ECMA-262) has been quite stable for some time, it is not standing still. A separate document, ECMA-257, extends the language with new native objects that facilitate creating and manipulating XML data. The shorthand name for this new ECMAScript for XML standard is E4X. In a way, it bridges JavaScript and the W3C DOM because the concepts of elements, attributes, child nodes, and the like are integral parts of the E4X scene. But E4X is also a natural extension to JavaScript in that XML is just another data type (albeit with some powerful methods and constructors).

The obvious outlet for E4X extensions is in AJAX applications, where the new objects facilitate, for example, obtaining an XML document's element data without the otherwise cumbersome DOM node tree parsing. Similarly, when the server side of an AJAX application needs to receive data in XML form from the client (notably in SOAP applications), E4X objects simplify the creation of XML content for transmission as data posted via an XMLHttpRequest object instance.

The E4X standard uses the term "property" to refer to what a DOM scripter considers to be an element or group of elements. That's partly because E4X syntax references elements via ECMAScript property syntax. Discussions in this chapter on the subject, however, tend to stick with calling an element an element to be consistent with the way DOM scripters are accustomed to thinking about those pieces of data.

Much of the development work of the E4X standard was spurred by the Mozilla Foundation. It's not surprising, therefore, that Mozilla-based browsers 1.8 and later would be the first ones to support E4X features. A few E4X constructs will cause script errors in browsers not equipped to handle them. While it is possible to keep most browsers away from E4X code (by specifying the required extension to a script element's type attribute: type="text/javascript; e4x=1"), not all browsers recognize the type extension as being different from the normal text/javascript, and will therefore choke on the E4X notation as the page loads.




Dynamic HTML. The Definitive Reference
Dynamic HTML: The Definitive Reference
ISBN: 0596527403
EAN: 2147483647
Year: 2004
Pages: 120
Authors: Danny Goodman

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net