Four basic interfaces of DOM

Source: Internet
Author: User
Tags abstract definition
In the DOM 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 with the node name. The following describes the four interfaces.

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.

Elements, text nodes, comments, and processing commands cannot be separated from the context of the document. Therefore, 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 the document interface IDL (Interface Definition Language) Definition and some commonly used attributes and methods can be found in many reference books, we will introduce it later in combination with actual examples.

Node interface 
Node interfaces play an important role in the entire DOM tree. A large part of Dom 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.

Similarly, we will explain in detail how to use the node interface in the following examples.

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 Dom, 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 will be automatically reflected in the nodelist object without Dom application.ProgramPerform other operations.

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

Namednodemap Interface 
The namednodemap interface object contains 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 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.

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.