XML

Summary

The DOM is a W3C standard that describes how the structure of XML and HTML documents can be expressed as a native data structure within various programming languages. The DOM standard is language neutral, and implementations exist for a number of languages, including JavaScript, Java, C++, Perl, and Visual Basic. In this tutorial, you learned about the various interfaces that make up the DOM and how you can access data stored within the DOM structure from JavaScript. Even though the syntax of the language you use with the DOM might differ significantly from the syntax used in these JavaScript examples, the means of accessing the DOM will be basically the same. On the other hand, you may be quite content to stick with JavaScript as your language of choice for interacting with the DOM.

Q&A

Q.

Why don't some of the example programs in this tutorial work in Mozilla Firefox and Opera?

A.

Unfortunately, some advanced XML features such as XML data islands and data binding vary from browser to browser, and aren't even supported in some browsers. This tutorial focuses on the Internet Explorer version of data islands and data binding. Mozilla Firefox has similar features although they are coded a little differently, while Opera has no support for either feature.

Q.

Can large documents create performance issues when I use the DOM?

A.

Yes. As you know, DOM parsers create a data structure that contains all of the data in an XML document, which means that all of the data is loaded into memory at once. If your XML document is really large (in comparison to the amount of RAM in the computer that your application runs on), performance issues can arise. In those cases, it may make more sense to use a SAX parser because it does not deal with the document as a whole. SAX is covered in the next tutorial, "SAX: The Simple API for XML."

Workshop

The Workshop is designed to help you anticipate possible questions, review what you've learned, and begin learning how to put your knowledge into practice.

Quiz

1.

From which interface in the DOM are all the others derived?

2.

The DOM is specific to which programming language?

3.

How do the NodeList and NamedNodeList interfaces differ?

4.

Which interfaces support attributes?

Quiz Answers

1.

All of the interfaces in the DOM are derived from the Node interface, with the exception of the NodeList interface.

2.

Sorry, this is a trick question! The DOM is not specific to any programming language.

3.

The NamedNodeList interface is an extension of the NodeList interfaceit adds support for retrieval of members using the node name.

4.

The Element and Entity interfaces support attributes.

Exercises

1.

Write a script that converts all of the attributes in an XML document into child elements of the elements that they were associated with.

2.

Write a program that shows the names of only those elements that have attributes and no children.