The Document Object Model W3C API Interface (DOM)

About

The Document Object Model (DOM) is one of the two programming models used to represent a XML document.

DOM defines the interface description of a Document Object that represents an XML document (and therefore of also all descendant technology such as HTML document, SVG, …).

It's the output of the parsing of a document (for instance, for HTML, see HTML - (Document) Parser).

The DOM exposes the hierarchical structure of the content, such as:

  • paragraph and table elements for HTML
  • node and attribute for XML

allowing their reference and manipulations.

The document object model (DOM) is a shared representation of the web document between the following w3c tools. Ie:

  • HTML for page content,
  • CSS for aesthetics,
  • JavaScript for interaction,
  • SVG for vector graphics,
  • XML …

It permits cooperation between this technologies.

Some related DOM-based APIs have been developed as well in the specifications for:

This document represents therefore any web page loaded in the browser and serves as an entry point for all scripts language (javascript, …) implementing this interface.

The Document Object Model standard is, above all, designed for structured document of document type (for example, articles and books and but not for data reprensentation).

The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update:

  • the content,
  • structure,
  • and style

of a document.

The DOM defines an API:

  • the objects and properties of all document elements,
  • and the methods to access them.

DOM functions can be used to:

  • create nodes,
  • remove nodes,
  • change contents,
  • traverse the node hierarchy.

The DOM presents an (XML|HTML) document as a tree-structure.

The DOM model involves creating in-memory objects representing an XML document with two parts:

  • an entire document tree (a tree structure)
  • and the complete infoset state

Once in memory, DOM trees can be:

  • navigated freely
  • and parsed arbitrarily (on the fly)

However, the entire representation of the document must be held in memory as objects for the duration of the document processing. It has therefore a large memory footprint and significant processor requirements.

This may not be an issue when working with small documents, but memory and processor requirements can escalate quickly with document size.

The DOM API is ideal for interactive applications because the entire object model is present in memory, where it can be accessed and manipulated by the user. On the other hand, constructing the DOM requires reading the entire XML structure and holding the object tree in memory, so it is much more CPU- and memory-intensive than a stream API.

Type of structured document

With DOM, you are free to create the semantics you need. However, you are also required to do the processing necessary to implement those semantics.

To get a full understanding of the kind of processing you need to do when searching or manipulating a DOM, it is important to know the kinds of document.

Attribute

Live

If a DOM object is said to be live, then the attributes and methods on that object must operate on the actual underlying data, not a snapshot of the data.

Documentation / Reference

Task Runner