Table of Contents
The Document Object Model, DOM for short, is an abstract data structure that represents XML documents as trees of nodes. Different interfaces in the org.w3c.dom package represent elements, attributes, parsed character data, comments, and processing instructions. All of these interfaces are sub-interfaces of the common Node interface that provides basic methods for navigating and pruning the tree.
The root of the tree is a Document object that represents a complete well-formed document. A parser reads an XML document from a stream and builds a Document object representing that XML document. The client program calls the methods of Document and the other DOM interfaces to navigate the tree and extract information from the document. Programs can also manipulate the tree in memory to add, delete, move, or change nodes in the tree. Programs can even create completely new documents from scratch in memory which are then written into an XML file.
The first version of DOM wasn’t an official specification, just the object model that Netscape Navigator 3 and Internet Explorer 3 implemented in their browsers. (Really, these were two different object models since they were only marginally compatible with each other.) This is sometimes called DOM Level 0.
DOM Level 2 cleaned up the DOM Level 1 interfaces. The big change was namespace support in the Element and Attr interfaces. In addition, DOM2 added a number of supplementary interfaces for events, traversal, ranges, views, and style sheets. I’ll address these in upcoming chapters. In 2002, all significant XML parsers that support DOM, support DOM Level 2. There’s not a lot of reason to worry about the difference between DOM1 and DOM2. From this point forward, I’m just going to teach DOM2.
DOM Level 3 is visible not far up the road. Parts of it are just beginning to be supported by bleeding edge parsers, most especially Xerces 2. In the core, DOM3 just adds a few missing pieces needed to allow DOM to fully support all Infoset properties. This includes the original encoding and base URI of the document. However, DOM3 will also add some crucial functionality missing from DOM2. In particular, DOM2 doesn’t provide a parser-independent means to create a new Document object, either by parsing a file or by building one from scratch in memory. DOM3 will provide standard ways of doing both. DOM3 is also going to add a lot more support for DTDs and schemas. But despite all its new features and functionality, DOM3 will not replace DOM2. Everything that works today in DOM2 will continue to work the same way in DOM3. DOM3 extends the DOM into new territory, but it doesn’t change what has gone before.
|Copyright 2001, 2002 Elliotte Rusty Haroldfirstname.lastname@example.org||Last Modified May 26, 2002|
|Up To Cafe con Leche|