The Document Object Model (DOM) is a W3C standardized programming interface that allows scripts to examine and modify the contents of the web browser. By the DOM, the composition of an HTML or XML document is represented as a set of objects – which can represent a window, a sentence or a style, for example – linked in a tree structure. Using the DOM, a script can modify the document present in the browser by adding or removing nodes from the tree.
- Model: A model is used to represent something. The DOM represents the document that is in the browser.
- Object: In programming, an object is a container that has properties and methods – which are variables and actions about what it represents. DOM objects can represent a window, a document, a sentence or a style.
- Document: The DOM is a document, such as a web page displayed in a browser. A web page starts with a tag followed by the tag in which the rest of the document is located. The DOM represents the document displayed by a tree structure, with nodes.
Implementation and Technical Aspects of DOM
The W3C specification stipulates the objects, methods and properties that a web browser must make available. The main object categories of a DOM tree are document, elements, and attributes.
Illustration: Naveen Ankireddy
DOM is used to represent the structure of a document and its elements in the form of a tree. It is therefore preferable to go through and memorize the entire document before you can perform the desired treatments. For this reason, programs using DOM often have a large memory footprint being processed. Conversely, from a given DOM tree, it is possible to generate documents in the desired markup language, which can in turn be manipulated by the DOM interface.
DOM is used to easily edit XML documents or access the content of web pages. In cases that do not require manipulating XML documents, but just reading them, the SAX method can also be chosen because it processes the elements sequentially without loading the document into memory. It is required when the size of the document exceeds the memory capacity.