Document Object Model
Document Object Model (DOM ) is a specification of an interface for accessing an HTML or XML documents. It is defined by the World Wide Web Consortium.
An implementation that meets this specification, is in the sense of object-oriented programming of a set of classes and methods, along with their attributes. It allows computer programs to dynamically change the contents of the structure and layout of a document.
- 4.1 DOM Level 0
- 4.2 DOM Level 1
- 4.3 DOM Level 2
- 4.4 DOM Level 3
The name " Document Object Model " is actually a misnomer, since DOM is defined not as a model, but as an interface ( Interface) for data access and is also referred to as the W3C. The text of label emphasizes, however, the basis of the interface well-defined object model whose validity is a prerequisite for the validity of the constructed thereon interface. At a higher level of abstraction is a model of an interface, namely the way to access objects or data.
DOM was originally created under the influence of at least two developments that significantly shaped the computer world in the recent past. Two is motivated by the need for the structured data in HTML and XML documents easily and be able to access uniformly.
At the same XML emerged as a common exchange format for human-readable representation of structured data, which built on the success of HTML. For processing XML documents a comprehensive, powerful and programming language independent interface was needed. DOM offers such and also defines additional interfaces for a comfortable dealing with XML documents.
Basics of DOM is an example
The following HTML code defines a table with the table element and various sub-elements:
|first name < / th>||Name < / th> tr> thead >|
|Donald < / td >|| Duck < / td >
< / table>
How it looks in a browser:
The DOM represents the table element and its subelements in the following tree structure:
This example can be the basic structure of the object model to discuss: Documents are logically represented as a tree. Nodes ( nodes ) are about " relationships " with each other in connection.
Types of relationships
The present structure is characterized by the following relations in the object model:
Starting from an arbitrary node at any other node is reachable via relationships.
Types of nodes
The most important types of nodes in the DOM are:
Attribute nodes are a special type of node, because they do not come as a node in the tree in front, which is formed mainly by the element nodes. Attribute nodes thus are not " children " of element nodes, but properties of them.
Processing a document
In the first step an existing document is read by the program and creates a document object. Based on this object may be accessed content, structure, and representation means of the methods of the API.
In particular DOM allows
At the end of the processing can be generated from the document object by so-called serialization a new XML or HTML document.
Standardization of DOM
DOM is a W3C standard since 1998, and has since been updated and expanded several times. There are several versions (levels ), each with different modules:
DOM Level 0
DOM Level 1
DOM Level 2
DOM Level 3