Chapter 20. Working with XML

One feature of the browser that doesn't get used as much is the capacity to hold and transform XML. Extensible Markup Language (XML) can be thought of as a specification for describing markup languages (like XHTML) but also as a container for data. It's used often as a transport format for Ajax requests just to hold and describe the data coming back.

In this chapter I'll be showing you how to load XML documents, use the XML DOM features of the browser that are similar to the HTML DOM features, and transform XML to XHTML using XSLT. Finally, you'll learn a little bit about JavaScript for XML, also known as E4X.

Loading XML

The way Internet Explorer and other browsers like Firefox implement the XML Document Object Model is different, not surprisingly. Microsoft used a similar technique in their XMLHttpRequest implementation, which was to leverage ActiveX. This had the advantage that their XML implementation could be used outside the browser in other programming languages that had access to COM. Some parts of the two implementations are quite similar, while others (like error handling) are quite different, as you will see.

Deserializing Text

When you take a string that contains XML and convert it to a properly formed XML document, that's called deserializing because you're taking an XML document that was strung together (that is, in serial) and reverting it to its original components. In this case, the document form of XML is very useful because you can work ...

Get JavaScript® Programmer's Reference now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.