Home > Articles

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

The Document Object Model

The Document Object Model (DOM) is a set of abstract interfaces that model the XML Infoset. The DOM Level 1 specification was designed prior to the Namespaces in XML recommendation and is not considered in this chapter. The DOM Level 2 specification is currently a W3C Candidate Recommendation and has already gained support from commercial and open-source XML processing software. For that reason, when this book refers to "the DOM," it is referring to DOM Level 2 or greater.

Like SAX, the DOM operates at the Infoset level and is devoid of angle brackets or character references. Additionally, the DOM is defined entirely in terms of abstract interfaces; implementations are free to implement these interfaces in any manner they choose. However, unlike streaming interfaces such as SAX, the DOM supports in-memory traversal, navigation, and modification of an abstract XML document. While the DOM currently does not mandate I/O functionality, most (if not all) implementations of the DOM interfaces support reading and/or writing XML 1.0 + Namespaces documents.

The DOM specification defines interfaces using the OMG's Interface Definition Language (IDL). IDL is a programming language-neutral language for defining programmatic types. To reduce the dependencies on external specifications, 6 the DOM also defines two language mappings: Java and ECMAScript (the standardized version of Javascript/Jscript). The primary difference between these two bindings relates to the handling of field accessors. For IDL interfaces that have attributes (OMG IDL attributes, not XML attributes), the ECMAScript language binding maps the attribute to a property. For example, the Node interface has an attribute named nodeValue.

interface Node {
  attribute DOMString nodeValue;
     :         :          :

Accessing nodeValue from ECMAScript is fairly trival.

node.nodeValue = "Hello, World";

The Java language binding maps IDL attributes to getXXX/setXXX methods, so the Java equivalent to the previous statement would look like this.

node.setNodeValue ("Hello, World");

IDL readonly attributes of course do not have a setXXX method.

  • + Share This
  • 🔖 Save To Your Account