Document Object Model
From Freepedia
Document Object Model (DOM) is an application programming interface to access HTML and XML documents. It is programming language and platform independent. Behind the interface the document is represented with an object-oriented model.
Different variants of DOMs were initially implemented by web browsers to manipulate elements in an HTML document. This prompted the World Wide Web Consortium (W3C) to come up with a series of standard specifications for DOM (hence called W3CDOM).
DOM puts no restrictions on the document's underlying data structure. A well-structured document can take the tree form using DOM.
Most XML parsers (e.g., Xerces) and XSL processors (e.g., Xalan) have been developed to make use of the tree structure. Such an 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 randomly accessed and manipulated. For XML-based applications, which involve a one-time selective read/write per parse, DOM presents a considerable overhead on memory. The SAX model is advantageous in such a case in terms of speed and memory consumption.
Contents |
Levels
The current DOM specification is Level 2, but some of the Level 3 specifications are now W3C Recommendations.
- Level 0
- Includes all the vendor-specific DOMs that existed before creation of DOM Level 1, e.g. document.images, document.forms, document.layers, and document.all. Note, this is not a formal specification published by the W3C but rather a reference to what existed before the standardisation process.
- Level 1
- Navigation of DOM (HTML and XML) document (tree structure) and to manipulate content (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) the DOM Level 3 Core; 2) the DOM Level 3 Load and Save; 3) the DOM Level 3 XPath; 4) the DOM Level 3 Views and Formatting; 5) DOM Level 3 Requirements; and 6) the DOM Level 3 Validation, which further enhance the DOM.
Use in web browsers
Different DOM implementations in different web browsers had led to inter-operability problems in the past. So it is common usage among web programmers to test first if a certain property is available before using it. The following code snippet shows how to test if key methods of the W3CDOM are available before attempting to execute code dependent on support for the W3CDOM.
if (document.getElementById && document.getElementsByTagName) {
// as the key methods getElementById and getElementsByTagName
// are available it is relatively safe to assume W3CDOM support.
obj = document.getElementById("navigation")
// other code which uses the W3CDOM
// .....
}
Microsoft's Internet Explorer browsers (version 5 (1999), ... version 6 (2001)) are as of 2005 the most common web browsers. They reasonably support many W3CDOM properties as do the Gecko based browsers like Mozilla and Firefox and others, so the problems of using the W3CDOM do not exist anymore to the extent as they did in 2000 where Internet Explorer 4x and Netscape 4.x were still widely used. This assumes of course that a vast majority of people do not use a web browser older than 6 years, which is in fact confirmed by browser usage statistics. The table in the article Comparison of layout engines (DOM) shows, which methods and attributes may be used safely given certain browser requirements.
Specifications
- Document Object Model (DOM) Level 1 Specification
- Level 2 Recommendations:
- Document Object Model (DOM) Level 2 Core Specification
- Document Object Model (DOM) Level 2 Views Specification
- Document Object Model (DOM) Level 2 Events Specification
- Document Object Model (DOM) Level 2 Style Specification
- Document Object Model (DOM) Level 2 Traversal and Range Specification
- Document Object Model (DOM) Level 2 HTML Specification
- Level 3 Recommendations:
- Level 3 Working Group Notes:
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)
- Dynamic HTML
External links
- W3.org on DOM
- Technology Reports
- Tutorials
- What does your user agent claim to support?
- What does each DOM Level bring?
- About the W3C Document Object Model (MSDN)
- W3C DOM scripts and compatibility tables (Quirksmode)
- Gecko DOM Reference
- khtml Library API Documentation
- Interfaces for ...



