Document Object Model |
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 programming 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 structure using DOM.
Most XML parsers (e.g., Xerces) and Extensible Stylesheet Language 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 Simple API for XML model is advantageous in such a case in terms of speed and memory consumption.
=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 DOM 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 (layout engine) based browsers like Mozilla Application Suite and Mozilla 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=
*[http://www.w3.org/TR/REC-DOM-Level-1/ Document Object Model (DOM) Level 1 Specification] *Level 2 Recommendations: **[http://www.w3.org/TR/DOM-Level-2-Core/ Document Object Model (DOM) Level 2 Core Specification] **[http://www.w3.org/TR/DOM-Level-2-Views/ Document Object Model (DOM) Level 2 Views Specification] **[http://www.w3.org/TR/DOM-Level-2-Events/ Document Object Model (DOM) Level 2 Events Specification] **[http://www.w3.org/TR/DOM-Level-2-Style/ Document Object Model (DOM) Level 2 Style Specification] **[http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ Document Object Model (DOM) Level 2 Traversal and Range Specification] **[http://www.w3.org/TR/DOM-Level-2-HTML/ Document Object Model (DOM) Level 2 HTML Specification] *Level 3 Recommendations: **[http://www.w3.org/TR/DOM-Level-3-Core/ Document Object Model (DOM) Level 3 Core Specification] **[http://www.w3.org/TR/DOM-Level-3-LS/ Document Object Model (DOM) Level 3 Load and Save Specification] **[http://www.w3.org/TR/DOM-Level-3-Val/ Document Object Model (DOM) Level 3 Validation Specification] *Level 3 Working Group Notes: **[http://www.w3.org/TR/DOM-Level-3-XPath/ Document Object Model (DOM) Level 3 XPath Specification] **[http://www.w3.org/TR/DOM-Level-3-Views/ Document Object Model (DOM) Level 3 Views and Formatting Specification] **[http://www.w3.org/TR/DOM-Requirements/ Document Object Model (DOM) Requirements]
=See also=
*DOM Events *Simple API for XML - 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=
*[http://www.w3.org/DOM/ W3.org on DOM] *[http://xml.coverpages.org/dom.html Technology Reports] *[http://xml.com/pub/rg/DOM_Tutorials Tutorials] *[http://www.w3.org/2003/02/06-dom-support.html What does your user agent claim to support] *[http://www.mozilla.org/docs/dom/reference/levels.html What does each DOM Level bring] *[http://msdn.microsoft.com/workshop/author/dom/domoverview.asp About the W3C Document Object Model] (MSDN) *[http://www.quirksmode.org/dom/contents.html W3C DOM scripts and compatibility tables] (Quirksmode) *[http://mozilla.org/docs/dom/domref/ Gecko DOM Reference] *[http://developer.kde.org/documentation/library/cvs-api/khtml/html/namespaceDOM.html khtml Library API Documentation]
*Interfaces for ... **[http://xml.apache.org/xerces-c/program-dom.html C++] **[http://www.w3.org/2003/01/dom2-javadoc/index.html Java] - W3C Document Object Model Level 2 **[http://interaction.in-progress.com/developer/dom/ Lisp] **[http://www.philo.de/xml/downloads.shtml Pascal] (Kylix) **[http://search.cpan.org/~tjmather/XML-DOM-1.43/ Perl] **[http://www.php.net/manual/en/ref.domxml.php PHP] **[http://www.python.org/doc/current/lib/module-xml.dom.html Python] **[http://libgdome-ruby.berlios.de/ Ruby] **[http://tclxml.sourceforge.net/tcldom.html TCL]|
|