Four basic interfaces in the DOM object model interface specification

Source: Internet
Author: User
Tags abstract definition

Four basic interfaces of the DOM object model

In the DOM object model interface specification, there are four basic interfaces: Document, node, nodelist, and namednodemap. Among the four basic interfaces, the document interface is the entry for document operations, which is inherited from the node interface. The node interface is the parent class of most other interfaces. interfaces such as javaset, element, attribute, text, and comment are inherited from the node interface. The nodelist interface is a collection of nodes that contain all the subnodes of a node. The namednodemap interface is also a set of nodes. Through this interface, you can establish a one-to-one ing between node names and nodes, so that you can directly access specific nodes by using node names. The following describes the four interfaces.

 

1. Document Interface

The document interface represents the entire XML/html document. Therefore, it is the root of the entire document tree and provides an entry for accessing and operating the data in the document.

Because elements, text nodes, comments, and processing commands cannot exist independently from the context of the document, the document interface provides a method to create other node objects, the Node object created using this method has an ownerdocument attribute to indicate who created the current node and the connection between the node and the document.

Shows the relationship between the document interface and other interfaces in the DOM tree:

The figure shows that the document node is the root node in the DOM tree, that is, the entry node for operations on the XML document. With the docuemts node, you can access other nodes in the document, such as instructions, annotations, document types, and root element nodes of the XML document. In addition, we can also see that in a DOM tree, the document node can contain multiple processing commands and comments as its subnodes, the document type node and the XML document root element node are both unique.

Details about Document Interface IDL (interfacedefinitionlanguage Interface Definition Language) and some of the commonly used attributes and methods can be found in many reference books.

 

2. node interface

Node interfaces play an important role in the entire DOM tree. A large part of DOM object model interfaces are inherited from node interfaces, such as element, ATTR, and cdatasection interfaces, all are inherited from node. In the DOM tree, the node interface represents a node in the tree. Shows a typical node interface:

The node interface provides a way to access the content and information of elements in the DOM tree, and provides support for element traversal in the DOM tree.

 

3. nodelist Interface

The nodelist interface provides an abstract definition of a node set. It does not include how to implement the definition of this node set. Nodelist is used to represent a group of nodes with sequential relationships, such as the subnode sequence of a node. In addition, it also appears in the return values of some methods, such as getnodebyname.

In the DOM object model, the nodelist object is "live". In other words, changes to the document are directly reflected in the relevant nodelist object. For example, if a nodelist object is obtained through DOM and the object contains a set of all subnodes of an element node, when the element node is operated by Dom (add, delete, and modify the child nodes in the node), these changes are automatically reflected in the nodelist object, the DOM object model application is not required to perform other operations.

Each item in nodelist can be accessed through an index. The index value starts from 0.

4. namednodemap Interface

Objects that implement the namednodemap interface include a set of nodes that can be accessed by name. However, note that namednodemap does not inherit from nodelist, and the nodes in the node set contained in it are unordered. Although these nodes can also be accessed through indexes, it only provides a simple way to enumerate nodes contained in namednodemap, it does not indicate that a sort order is defined for the nodes in namednodemap In the DOM object model specification.

Namednodemap represents the one-to-one correspondence between a group of nodes and their unique names. This interface is mainly used to represent attribute nodes.
Like nodelist, namednodemap objects in Dom are also "live.

 

Four basic interfaces in the DOM object model interface specification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.