What Is an Object Model? An object model represents a document by providing a set of interfaces (methods and
properties) to the programmer. This set of interfaces completely shields a programmer
from the actual syntax of the data behind this interface. The data behind the interface can
be an XML document, legacy database, or an application that provides an XML stream.
In the case of an XML document, a parser is used to check a document’s validity, to build
an in-memory representation of the document, and to expose the object model to the
programmer. For a legacy database, an object that can read the database in its native
form sits on top of the database, allowing programmers to use the DOM to access the
original data. This method allows an existing database to provide on-the-fly conversion to
XML.
An analogy of the object model in the car industry is how every car is used in a similar
fashion. Each car has a steering wheel, gas pedal, and brake pedal. The number of
cylinders, the number valves, and the horsepower rating of the engine don’t matter to the
interface; the way a driver uses a car remains the same. All compliant XML DOM
implementations expose the same set of classes to the programmer, regardless of the
internals. Of course, some cars have air bags, CD players, and other features. In the
XML world, as we see later on, some parsers have included additional functionality that
you can’t guarantee in every parser.
A standard object model is necessary to alleviate the many problems that occurred when
Netscape and Microsoft provided different implementations of the HTML object model
known as Dynamic HTML (DHTML). Web sites that make heavy usage of DHTML through
scripting engines often need to have multiple versions of the Web site—one for Navigator
and one for Internet Explorer. Also, a standard object model allows developers to write
programs that use XML without committing themselves to one company’s parser.
- 101 -
Types of DOM The DOM also addresses the need for an Object Model in HTML as well as in XML. A
well formed HTML document is also an XML document. This relationship is shown in the
DOM, where the XML DOM is referred to as the Core DOM, and the HTML DOM is an
extension to the Core specification.