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.

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

Prev Article:

Next Article:

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.

12 Hottest Geek Girls on Twitter

So, you have seen the 12 Hottest Geek Girls (via Digg). However, they forgot to link them to their, hmmmmmm errrr, Twitter profiles so you can follow them. Or perhaps they felt -- they're popular ...13th Oct, 2009

Great Indian Developer Summit 2009

I got a Press Release of the upcoming GIDS '09 and here is an excerpt. The summit's program covers Java, REST, Unit testing, Groovy, Spring, Struts 2.0, SOA, Cloud Computing, Web Services, JRuby, RoR, Ruby, JVM, ...21st Jan, 2009

The flourishing gun market in Pakistan

VICE Travel: Darra, Pakistanby Top-Notch112 (Via: Deep Green Crystals) 20th Jan, 2009

Angry Ringtone for iPhone and others

[audio:http://audio.brajeshwar.com/angry-ring-ring.mp3] The ANGRY RINGTONE for iPhone. (Click the PLAY button above!) Download * iPhone Ringtone (.m4r) * MP3 Ringtone (.mp3) * Zipped (both .m4r and .mp3) To use it as an iPhone Ringtone; just double click the file "angry-ring-ring.m4r" and it ...15th Jan, 2009

IIM Ahmedabad's Leverage 2009

Leverage, the Venture Capital and Private Equity Club of IIM Ahmedabad and the Centre for Innovation Incubation and Entrepreneurship bring to you the 1st edition of the Venture Capital and Private Equity Conference on the ...12th Jan, 2009

View the Sidenotes Archive

Play the Penguin Game

Recommended

  • o! Just Me Of colorful cultures, entertainment, media, life hacks, music, books and movies from hollywood & bollywood.
  • Downloads All downloads, Free and Open Source.
  • AS 2.0 Reference Reference for ActionScript 2.0 Programming Language used in Flash. Primarily stashed here for my own personal reference.
  • ActionScript 3.0 Reference Flash/Flex ActionScript 3.0 Reference.
  • Ode to Apple Dedicated to Apple – Mac, iPhone, iPod, iTunes, Quicktime, Apple TV and all the awesome softwares for the Apple Mac.
  • Not Safe for Work Ever clicked a link and felt embarrassed with the content in front of your co-workers? Ever caught unaware because the funny link your friend sent was a little beyond funny? Let’s minimize that with NSWF.

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.

Photos

More photos on Flickr

Member of 9rules Network

Since its inception on 11th June, 2001, "Brajeshwar" has 979 Articles and 6,657 comments, contained within 17 categories and 1,591 tags.