XML

What Is the DOM?

If you're a seasoned HTML or JavaScript expert, you might already be familiar with the Document Object Model, or DOM. When you're creating dynamic web pages, it's common to access elements on a web page from JavaScript using the DOM. The principles involved are basically the same for accessing XML documents using the DOM.

The DOM is a standard method for exposing the elements in a document as a data structure in your programming language of choice. In other words, the DOM provides access to all the pieces and parts of a web page or XML document. A program, called a DOM parser, reads through the XML code in a file (or from some other source of input), and provides a data structure that you can access from your application. In the XML world, the DOM parser can also write its data structure out as XML so that you can save any changes that you make to the data structure.

Like XML itself, the DOM is a standard developed by the World Wide Web Consortium (W3C). Most of the details of how the DOM works are left up to the specific implementations. It's important to understand that there are multiple levels of the DOM. DOM level 1 is concerned with basic XML and HTML. DOM level 2 adds specifications for XML namespaces, Cascading Style Sheets (CSS), events, and various traversal schemes. DOM level 3, which is currently still in the works, will round out its XML coverage, include support for more user interface events, and support XPath (see Getting Started with XSL, and Transforming XML with XSLT for more on XPath). This tutorial focuses on how to use level 1 of the DOM since it is the most widely implemented. You can find the DOM specifications online at http://www.w3.org/DOM/.

By the Way

All of the DOMs prior to the W3C's creation of the Level 1 DOM are loosely referred to as the Level 0 DOM. However, this isn't truly a single DOM but it instead a grouping of all the vendor-specific DOMs that ran rampant in the early days of the dynamic web.