Thursday, March 13, 2008

E4X (ECMAScript for XML)

E4X is a scripting language extension that adds native XML support to ECMAscript. It does this by providing access to the XML document in a form that feels natural for ECMAscript programmers. The goal is to provide a simpler API for accessing XML documents, than other common APIs, such as DOM or XSLT.

Lets take a look at a few examples of how you can read XML data using E4X.

You will be able to create variables of type XML by parsing a String. But XML literals will now be supported as well:

Most powerful of all, E4X supports “predicate filtering” using the syntax .(condition), which lets you pick out nodes or attributes that meet a condition you specify using a Boolean _expression_. For example, you can pick out the employee with a particular social security number like this, and get her state: