W3C's Document Object Model (DOM) is a standard Application Programming Interface (API) to the structure of documents; it aims to make it easy for programmers to access components and to delete, add, or edit their content, attributes and style. In essence, the DOM makes it possible for programmers to write applications which work properly on all browsers and servers and on all platforms. While programmers may need to use different programming languages, they do not need to change their programming model.
W3C's DOM thus offers programmers a platform- and language-neutral program interface which will make programming reliably across platforms with languages such as Java and ECMAScript a reality.
Markup languages such as HTML or SVG provide different ways to include some programming or scripting in the document, directly or by links.
Please read and heed the Web Content Accessibility Guidelines before using scripts in your documents, in particular guideline 6.
Specifications of existing scripting languages such as ECMAScript (an industry-standard scripting language based on JavaScript and JScript) only give the syntax, the grammar, and the basic types' functionalities (String, Object, Number, ...). These specifications don't give the user access to user agent functions (menus, scrollbars, user events, ...) or to the document (text contents, markup structure, style sheets, ...). This is where the DOM comes in.
In 1996, the W3C released the first version of the Extensible Markup Language (XML) specification. XML has been used to create a variety of applications: editors, repositories, databases, B2B systems, Web content, network protocols, etc.
This specification provides the syntax and the grammar for XML. However, an API is needed in order for the user to access the XML content and structure in an application.
Generic APIs for XML can be mostly classified in two categories: event-based or tree-based. The DOM is a generic tree-based API for XML. For more information about event-based APIs and a comparison with tree-based APIs, read the SAX documentation "What is an Event-Based Interface?" or the DOM Frequently Asked Question (FAQ) "What is the relationship between the DOM and SAX?". Non-generic APIs for XML are not covered in this document.
// get the HTML body element from the document var childs = doc.getElementsByTagName("body"); // there is one HTML body element for each HTML 4.0 document var body = childs.item(0); // change the value of the CSS2 color property body.style.color = "black";
For other examples, check the DOM Level 2 demo used in the main DOM page or the DOM Level 1 Table of Contents demo.
The DOM Architecture is divided into various modules. Each module addresses a particular domain. Domains covered by the current DOM API are XML, HTML, Cascading Style Sheets (CSS), and tree events. Future domains can be the rendered content (that is, the content displayed on the screen which might differ from the input document), user agent function, etc.
The DOM Core defines a tree-like representation of the document, also referred as the DOM tree, enabling the user to traverse the hierarchy of elements accordingly.
Refer also to the DOM Range and Traversal modules to manipulate the tree elements/structure defined in the DOM Core.
The XML DOM extends the Core platform for specific XML 1.0 needs, such as processing instructions, CDATA, and entities.
The HTML DOM defines a set of convenient easy to use ways to manipulate HTML documents. The initial HTML DOM only describes methods, such as how to access an identifier by name, or a particular link. The HTML DOM is sometimes referred to as DOM Level 0 but has been imported into DOM Level 1.
This part defines XML-tree manipulation oriented events with tree mutation and user-oriented events such as mouse, keyboard, and HTML-specific events.
The DOM CSS defines a set of convenient, easy to use ways to manipulate CSS style sheets or the formatting of documents.
Loading an XML document into a DOM tree or saving a DOM tree into an XML document is a fundamental need for the DOM user. This module includes a variety of options controlling load and save operations.
This module defines a set of methods to modify the DOM tree and still make it valid.
The DOM XPath defines a set of convenient, easy to use functions to query
a DOM tree using an XPath 1.0 expression, such as evaluate
.
The DOM Activity, started in August 1997 in the User Interface Domain, presently contains only one Working Group: the DOM Working Group [Members only]. The Activity was moved to the Architecture Domain in November 2000. The duration of the DOM Activity is through 2004-06-30.
The DOM Working Group is a member of the HyperText Coordination Group and has a liaison with the XML Coordination Group. The Chair of the DOM Working Group is Philippe Le Hégaret.
The DOM Working Group defines the DOM modules in a succession of Levels. Two Levels (1 and 2) are already Recommendations, except for DOM Level 2 HTML which is in Last Call. The Working Group is now working on Level 3.
The DOM requirements contains all requirements for each Level, and is regularly updated to reflect the requirements of the latest Level.
Functionalities equivalent to the ones exposed in Netscape Navigator 3.0 and Microsoft Internet Explorer 3.0 are informally referred to as "Level 0". There is no W3C specification for this Level.
DOM Level 1 was completed in October 1998 and provides support for XML 1.0 and HTML 4.0.
DOM Level 2 was completed in November 2000 extending Level 1 with support for XML 1.0 with namespaces, adding supports for Cascading Style Sheets (CSS), events such as user interface events and tree manipulation events, and enhancing tree manipulation methods (tree ranges and traversal mechanisms). Level 2 HTML is a W3C Recommendation since January 2003.
DOM Level 3 is currently under development. Level 3 will extend Level 2 by finishing support for XML 1.0 with namespaces aligning the DOM Core with the XML Infoset, adding support for XML Base, and extending the user interface events (keyboard). Level 3 will also add support for validation, the ability to load and save a document, explore further mixed markup vocabularies and their implications on the DOM API ("Embedded DOM"), and will support XPath.
Note: The DOM Working Group has released a public Working Draft of the Views and Formatting model. The DOM Working Group is waiting for more experience and experimentation before going further.
Note: The DOM Working Group has released a W3C Note on the Abstract Schemas model. This document is no longer a work item of the Working Group.
The DOM Working Group is not the only Working Group within the W3C to produce APIs and extensions to the DOM architecture. Other DOM modules include:
The W3C DOM Activity is developing the DOM Conformance Test Suites in coordination with NIST (National Institute of Standards and Technology) and the public community, with help from a few W3C Members. A first version was released in February 2002.
The W3C DOM Working Group is a royalty-free Working Group, as defined in the Current Patent Practice Note. A list of disclosures from the Working Group participants is available.
Today, the W3C is not aware of any patents that are essential to implement the DOM specifications. Therefore, it is the W3C's opinion that the DOM specifications can be implemented on a royalty-free basis.
DOM Level 3 Core, Load and Save, and Events are in Last Call. DOM Level 3 XPath and Validation is a Candidate Recommendation.