Francais | English | Espanõl

Document Object Model

From Wikipedia, the free encyclopedia

Jump to: navigation, search

Document Object Model (DOM) is a description of how an HTML or XML document is represented in a tree structure. DOM provides a structure that facilitates access to the elements of an HTML or XML document by scripting languages with object oriented features (e.g., JavaScript).

Various interfaces were initially implemented by web browsers to manipulate elements in an HTML document through JavaScript. This prompted the World Wide Web Consortium (W3C) to create a series of specifications to standardize implementations for increased interoperability; thus the W3C Document Object Model (W3C DOM) was born. The W3C specifications are platform and language independent. The previous vendor-specific interfaces were dubbed intermediate DOMs.

A simple example of its use is as follows:

To access an element in the DOM, the programmer could type document.getElementById("elementID"). This is an improvement over previous Web browser implementations of DOM element access. Internet Explorer, before coming into DOM compliance, necessitated that the developer access the DOM via an array of all elements; for example, document.all.[elementName]. While this was usable, it was more cumbersome than methods defined in the W3C DOM. The Gecko rendering engine, exhibited in Firefox and all of its derivatives, has been W3C‐compliant for quite some time.

The tree-based implementation requires that the entire content of a document be parsed and stored in memory. Hence, DOM is best used for applications where the document elements have to be accessed and manipulated in an unpredictable sequence and repeatedly. If the application involves a sequential or one-time selective read or write per processed document, DOM presents a considerable overhead. The sequential SAX model is advantageous in such a case in terms of speed and memory consumption.

Contents

[edit] Levels

The W3C DOM specifications are divided into levels, each of which contains required and optional modules. To claim to support a level, an application must implement all the requirements of the claimed level and the underlying levels. An application may also support vendor-specific extensions if they don't conflict with the W3C standards. As of 2005, Level 1, Level 2, and some modules of Level 3 are W3C Recommendations which means they have reached their final form.

Level 0 
The application supports an intermediate DOM, which existed before the creation of DOM Level 1. Examples include the DHTML Object Model or the Netscape intermediate DOM. Level 0 is not a formal specification published by the W3C but rather a shorthand that refers to what existed before the standardization process.
Level 1 
Navigation of DOM (HTML and XML) document (tree structure) and content manipulation (includes adding elements). HTML-specific elements are included as well.
Level 2 
XML namespace support, filtered views and events.
Level 3 
Consists of 6 different specifications:
  1. DOM Level 3 Core;
  2. DOM Level 3 Load and Save;
  3. DOM Level 3 XPath;
  4. DOM Level 3 Views and Formatting;
  5. DOM Level 3 Requirements; and
  6. DOM Level 3 Validation, which further enhances the DOM

[edit] Use in web browsers

DOM Inspector inspecting Wikipedia's main page

Since each web browser used to exclusively support its own intermediate DOM, interoperability problems were numerous. In order to be cross-browser compatible, that is, support multiple browsers, large parts of Dynamic HTML code had to be rewritten for each browser to be supported. A common DOM promised to greatly simplify the development of complex web applications.

W3C DOM Level 1 has been a recommendation since 1 October, 1998. The standardization effort did not bring forth an immediate change, since non-conformant browsers such as Internet Explorer 4.x and Netscape 4.x were still widely used in 2000. As of 2005, large parts of W3C DOM are well‐supported by common JavaScript-enabled web browsers, including Microsoft Internet Explorer (version 5 (1999) and version 6 (2001)), Gecko-based browsers (like Mozilla and Firefox), Opera, Konqueror, and Safari. Web developers are starting to mostly or solely rely on W3C DOM, since it allows browser compatibility with a large audience.

The article Comparison of layout engines (DOM) shows which methods and attributes may be used safely given certain browser requirements.

[edit] Specifications

[edit] See also

  • DOM Events
  • SAX - A set of APIs for accessing and manipulating XML documents in a sequential manner.
  • JDOM - A Java-based document object model for XML that integrates with DOM and SAX and uses parsers to build the document.
  • Comparison of layout engines (DOM)
  • Ajax - A methodology employing DOM in combination with techniques for retrieving data without reloading a page.
  • ECMAScript

[edit] External links

cs:Document Object Model de:Document Object Model es:Document Object Model fa:مدل شیء‌گرای سند fr:Document Object Model ko:문서 객체 모델 it:Document Object Model he:Document Object Model nl:Document Object Model ja:Document Object Model no:Document Object Model pl:Obiektowy model dokumentu pt:Modelo de Objeto de Documentos ru:DOM fi:DOM sv:Document Object Model th:Document Object Model vi:DOM uk:Об'єктна модель документа zh:文档对象模型

Personal tools