E4X or ECMAScript for XML in Flash

Somewhere around the second quarter of this year, RichInternet.de mentioned about one of their message about E4X on FlexCoders. With the announcement of Flash Player 8.5, Flex Builder 2 and eventually the next Flash IDE, version 9 that will support the much anticipated ActionScript 3.0, it is about time we look back to that topic.

E4X Specification states, E4X adds native XML datatypes to the ECMAScript language, extends the semantics of familiar ECMAScript operators for manipulating XML objects and adds a small set of new operators for common XML operations, such as searching and filtering. It also adds support for XML literals, namespaces, qualified names and other mechanisms to facilitate XML processing.

What does E4X have to do with ActionScript?

ECMA - AS
We know that ActionScript’s core language is based on ECMAScript. But ECMAScript (ECMA-262) had no way of working with XML Data. ActionScript 1.0 and 2.0 had classes and methods for working with XML data, they are however were not based on ECMAScript standard.

ECMA does XML
With the new ECMAScript Edition 4, it defines a new set of classes and functionality for working with XML Data. Well, these classes and functionality are what is called E4X or more appropriately ECMAScript for XML.

Benefits
Well, it will make ActionScripting easier, simpler, cool!

  • Simple - E4X makes it easier to write and understand code while working with XML Data
  • Consistent - Methods and reasoning behind E4X is consistent and consistent with other part of ActionScript
  • Same as what we have been doing - You can now manipulate XML data with well-known operators like the dot operator (.)

Somewhere around the second quarter of this year, RichInternet.de mentioned about one of their message about E4X on FlexCoders. With the announcement of Flash Player 8.5, Flex Builder 2 and eventually the next Flash IDE, version 9 that will support the much anticipated ActionScript 3.0, it is about time we look back to that topic.

E4X Specification states, E4X adds native XML datatypes to the ECMAScript language, extends the semantics of familiar ECMAScript operators for manipulating XML objects and adds a small set of new operators for common XML operations, such as searching and filtering. It also adds support for XML literals, namespaces, qualified names and other mechanisms to facilitate XML processing.

What does E4X have to do with ActionScript?

ECMA - AS
We know that ActionScript’s core language is based on ECMAScript. But ECMAScript (ECMA-262) had no way of working with XML Data. ActionScript 1.0 and 2.0 had classes and methods for working with XML data, they are however were not based on ECMAScript standard.

ECMA does XML
With the new ECMAScript Edition 4, it defines a new set of classes and functionality for working with XML Data. Well, these classes and functionality are what is called E4X or more appropriately ECMAScript for XML.

Benefits
Well, it will make ActionScripting easier, simpler, cool!

  • Simple - E4X makes it easier to write and understand code while working with XML Data
  • Consistent - Methods and reasoning behind E4X is consistent and consistent with other part of ActionScript
  • Same as what we have been doing - You can now manipulate XML data with well-known operators like the dot operator (.)

    Ok, so let us look at something
// Let us have some XML Data as literals for simplicity sake
// and for the FlashKnights, I have a big list, what you see here is just the beginning, ;-) var myXML:XML =
<flashknights>
	<knight id='1'>
		<fName>Mike Chambers</fName>
		<url>http://weblogs.macromedia.com/mesh/</url>
	</knight>
	<knight id='2'>
		<fName>Branden Hall</fName>
		<url>http://www.waxpraxis.org/</url>
	</knight>
	<knight id='3'>
		<fName>Colin Moock</fName>
		<url>http://www.moock.org/blog/</url>
	</knight>
	<knight id='4'>
		<fName>Grank Skinner</fName>
		<url>http://www.gskinner.com/blog/</url>
	</knight>
	<knight id='5'>
		<fName>Guy Watson</fName>
		<url>http://www.flashguru.co.uk/</url>
	</knight>
<flashknights>

Now, we would do something like
trace (myXML.knight[0].fName); // Mike Chambers
trace (myXML.knight.(@id==5).fName); // Guy Watson (look at that @ which is supported by E4X)
trace (myXML.knight.(fName=="Grank Skinner").url); // http://www.gskinner.com/blog/

Hmmm, while on the topic of E4X, Jesse once exclaimed, “node.child[0] … pimp … can it get any easier?”

See, we are doing away with the DOM-style APIs like firstChild, nextSibling, etc., with E4X we just dot down to grab the node you want. Multiple nodes are indexable with [n], similar to the elements of an Array. E4X allows us to write less code and execute it faster because more processing can be done at the native level.

Backward ActionScript Compatibility
E4X have an XML Class, to avoid conflict with the same, the XML Class in ActionScript 2.0 was renamed to XMLDocument and I am sure, ActionScript 3.0 will sport the same. As the news is ripe with the fact that E4X is making it into AS 3.0, we can expect the core classes to be part of AS 3.0 and the legacy classes still packaged with Flash so we can still use them if needed be.

Reference Articles;


Don't like it? There are lots of published articles, pick a random one.

oCricket

Brajeshwar posted this article on Fri, Oct 7th, 2005 at 7:08 am
Categorized under Technology

Prev Article: Dude, version it with CVSDude

Next Article: AS3, Player 8.5, Flex 2 news, straight from the source


Possibly Related Articles

Archives: Visit the Archives for more articles.

Comments Post Yours

There are one response so far. You can follow any responses to this entry through the RSS feed. You can skip to the end and leave a response. Pinging is currently not allowed.

  1. This theme is very interesting, with attention I will read next registration fees.

Post yours

Sidenotes

Quick notes, scribbles, somehow related to this website and to what I do. Or perhaps I'm just plain lazy to make them into a full article.

Fedora 10 Released

Let's talk history! Fedora was created in late 2003 as a Linux based Operating System which gives the users an admittance from anywhere in the world to the most up-to-date free and open source software ...28th Nov, 2008

Top 25 Hottest Indian Web Companies

Note: User submitted article. Personally, I would advise not to take this video seriously. 21st Nov, 2008

India gets ready for Free and Open Source Software

Over the years, FOSS.in has attracted thousands of participants, and the speaker roster reads like a "Who's Who" of FOSS contributors from across the world. FOSS.in is a non-commercial event organised and run entirely by FOSS ...21st Nov, 2008

Cooliris for the iPhone

Cooliris is the browser extension that revolutionizes the way you view media on your computer. It is now available as an application for your iPhone! Cooliris for the iPhone allows you to search the web ...22nd Oct, 2008

Adobe releases Flash Player 10 (Mac, Win & Linux)

Adobe have released the shipping version of Flash Player 10 for Mac, Windows and Linux. More about Flash Player 10 * About Flash Player 10 * Get Flash Player 10 (Official Release version 10.0.12.36) * Download Debug and Standalone ...15th Oct, 2008

View the Sidenotes Archive

Play the Penguin Game

Recommended

  • oCricket oCricket is about Cricket and people enthusiastic about it.
  • Downloads All downloads, Free and Open Source.
  • o! Just Me Of colorful cultures, entertainment, media, life hacks, music, books and movies from hollywood & bollywood.
  • ActionScript 3.0 Reference Flash/Flex ActionScript 3.0 Reference.
  • AS 2.0 Reference Reference for ActionScript 2.0 Programming Language used in Flash. Primarily stashed here for my own personal reference.
  • Ode to Apple Dedicated to Apple - Mac, iPhone, iPod, iTunes, Quicktime, Apple TV and all the awesome softwares for the Apple Mac.
  • My Special Job My Special Job is a place where you can look for your weird necessities, strangely superb employees, when your need are more of those hackers, geeks, and ultimate rockstars in the Internet Technology.

Download free Brajeshwar Wordpress Theme

Brajeshwar

Brajeshwar I firmly believe in keeping things simple, easy for users and I envison pushing the technical envelop time and again for the betterment of viable commercial and practical applications. More about me.

Brajeshwar's affinity with Adobe

My Photos

More photos on Flickr

Member of 9rules Network

Since its inception on 11th June, 2001, "Brajeshwar" has 903 Articles and 6,149 comments, contained within 21 categories and 1,384 tags.