DOM
Document Object Model
What is DOM ?
The Document Object Model (DOM) is a programming interface for web documents. It represents the page so that programs can change the document structure, style, and content. The DOM represents the document as nodes and objects; that way, programming languages can interact with the page.The principal standardization of the DOM was handled by the World Wide Web Consortium (W3C), which last developed a recommendation in 2004. With the Document Object Model, programmers can build documents, navigate their structure, and add, modify, or delete elements and content. Anything found in an HTML or XML document can be accessed, changed, deleted, or added using the Document Object Model, with a few exceptions — in particular, the DOM interfaces for the XML internal and external subsets have not yet been specified.
Architecture of DOM
As per the above diagram let’s dive into the concept:
The DOM (Document Object Model) tree structure is a way of representing the structure of an HTML or XML document as a tree of objects. Each object in the tree represents a part of the document, such as an element, text content, or attribute.The DOM tree has a hierarchical structure, with parent and child nodes. A node’s parent node is the node that directly encloses it, while its child nodes are the nodes that it directly encloses. The hierarchy of the tree reflects the structure of the document, with parent elements enclosing their child elements.For example, consider the following HTML code:
<body>
<h1>Hello All</h1>
<p>This is a paragraph.</p>
</body>
In the DOM tree, the body
element would be the parent node to the h1
and p
elements, which would be child nodes. The text content "Hello World" and "This is a paragraph." would be text nodes within the h1
and p
elements, respectively.
Limitations of DOM
- Document Object Model was strongly influenced by “Dynamic HTML”, in Level 1, it does not implement all of “Dynamic HTML”. In particular, events have not yet been defined.
- The Document Object Model is not a way of persisting objects to XML or HTML. Instead of specifying how objects may be represented in XML, the DOM specifies how XML and HTML documents are represented as objects, so that they may be used in object oriented programs.
- The Document Object Model is not a set of data structures, it is an object model that specifies interfaces.
- The Document Object Model does not define “the true inner semantics” of XML or HTML. The semantics of those languages are defined by W3C Recommendations for these languages.
- The DOM is a programming model designed to respect these semantics. The DOM does not have any ramifications for the way you write XML and HTML documents; any document that can be written in these languages can be represented in the DOM.
- The Document Object Model is not a binary specification. DOM programs written in the same language will be source code compatible across platforms, but the DOM does not define any form of binary interoperability.
- The Document Object Model, despite its name, is not a competitor to the Component Object Model (COM). The DOM is a set of interfaces and objects designed for managing HTML and XML documents. The DOM may be implemented using language-independent systems like COM or CORBA; it may also be implemented using language-specific bindings .