Chapter 20. E4X—Native XML Processing
IN THIS CHAPTER
Using the XML object
Adding elements and attributes
Selecting records
Serializing XML objects to text
With the rise in popularity of Ajax (Asynchronous JavaScript and XML) connectivity in recent years, it's become commonplace for web developers who might otherwise never stray beyond the bounds of HTML to work with XML (Extensible Markup Language). In fact, XML has been considered so fundamental to everyday web development that the ECMA has incorporated it into the very syntactical fabric of JavaScript. We can now write unquoted XML markup right into our JavaScript statements—as permitted by the most recent browsers.
This new feature of JavaScript syntax places XML uniquely on both sides of a major divide. Every other aspect of scripting is either part of the core JavaScript language or part of the DOM (Document Object Model). XML is now a member of both camps.
We discuss techniques for transmitting XML between client and server in Chapter 39, "Ajax, E4X, and XML" (on the CD).
XML
Briefly, XML is a markup language designed to contain and transmit textual data. It consists of nested elements marked up with three types of tag—matching begin- and end-tags
<hobby>music</hobby>
and empty-element tags
<breathe/>
Elements can contain attributes, which are name/value pairs that reside within the opening or empty tag:
<fax location="home" call-first="true">123-456-7890</fax>;
Unlike HTML and XHTML, in which element and attribute name choices are constrained ...
Get JavaScript® Bible, Seventh Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.