Main Page

ECMAScript for XML

Note that even though this example is syntactically correct, it causes an error in browsers other than
Mozilla when it is executed because neither function (defineGetter() or
) is defined.
Microsoft hasn’t updated its browser-based implementation of JavaScript since Internet Explorer 5.5 was
released. What it has done, however, is include a language called JScript.NET in the .NET Framework.
JScript.NET is, for all intents and purposes, an implementation of ECMAScript Edition 4 with some
Microsoft-specific additions added for good measure. However, it can’t be used as a client-side scripting
language in Internet Explorer, only as a server-side language in ASP.NET or as a standalone application
(yes, JScript.NET can be compiled).
Unlike other versions of JavaScript, JScript.NET is a compiled language capable of becoming a stan-
dalone executable file. It is compiled down to the same .NET machine code and executed using the
same Common Language Runtime (CLR) as both Visual Basic.NET and C#. Although it is beyond the
scope of this book to discuss the full potential and scope of JScript.NET, more information is available
on Microsoft’s Web site at
ECMAScript for XML
In 2002, a group of companies led by BEA Systems proposed an extension to ECMAScript to add native
XML support to the language. At that point, XML was starting to gain popularity, and the companies
wanted to make sure that ECMAScript was in the forefront of this next technology wave. In June 2004,
ECMAScript for XML (E4X) was released as ECMA-357. E4X is not its own language; rather, as origi-
nally intended, it is an optional extension to the ECMAScript language. As such, E4X introduces new
syntax for dealing with XML, as well as for XML-specific objects.
E4X stays away from implementing the current XML standards, such as SAX, XPath, and DOM, and
instead presents a unique way of creating and manipulating XML documents. The E4X approach
takes aspects from technologies such as DOM, XPath, and XSLT, although it doesn’t map specifically
to either one.
For example, suppose you were dealing with the following XML code:
<employee position=”Software Engineer”>
<name>Nicholas C. Zakas</name>
<employee position=”Salesperson”>
<name>Jim Smith</name>
This XML could be assigned to an ECMAScript variable by using the following code:
var oXml = <employees>
<employee position=”Software Engineer”>
<name>Nicholas C. Zakas</name>
The Evolution of JavaScript
23_579088 ch20.qxd 3/28/05 11:44 AM Page 605

JavaScript EditorFree JavaScript Editor     Ajax Editor