O'Reilly logo

Professional: JavaScript® for Web Developers, Third Edition by Nicholas C. Zakas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 19

ECMAScript for XML

WHAT’S IN THIS CHAPTER?

  • Additional types introduced by E4X
  • Using E4X for XML manipulation
  • Syntax changes

In 2002, a group of companies led by BEA Systems proposed an extension to ECMAScript to add native XML support to the language. In June 2004, ECMAScript for XML (E4X) was released as ECMA-357, which was revised in December 2005. E4X is not its own language; rather, 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.

Though browser adoption has been slow, Firefox versions 1.5 and later support almost the entire E4X standard. This chapter focuses on the Firefox implementation.

E4X TYPES

As an extension to ECMAScript, E4X introduces the following new global types:

  • XML — Any single part of an XML structure
  • XMLList — A collection of XML objects
  • Namespace — Mapping between a namespace prefix and a namespace URI
  • QName — A qualified name made up of a local name and a namespace URI

Using these four types, E4X is capable of representing all parts of an XML document by mapping each type, specifically XML and XMLList, to multiple DOM types.

The XML Type

The XML type is the most important new type introduced in E4X, because it can represent any single part of an XML structure. An instance of XML can represent an element, an attribute, a comment, a processing instruction, or a text node. The XML type inherits from the Object type, so it inherits all of the default ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required