Structure and access of the Html DOM tree (1)

Source: Internet
Author: User

Do you know the concept of the Html DOM tree? Here we will share with you, dom?entobjectmodel) the parser parses the XML document at one time and generates an object tree in the memory to describe this document.

Html DOM tree

1. Html DOM tree

All types of XML parsers require that the processing object be a "well-formed" XML document, and some can verify the validity according to DTD or XMLSchema. dom?entobjectmodel) the parser parses the XML document at one time, generate an object tree in memory to describe this document.

DOM is a platform-and language-independent interface that allows programs and scripts to dynamically access and modify the content, structure, and type of a document. It defines a series of objects and methods to perform various random operations on the nodes of the Html DOM tree:

◆ Document Object: as the highest node of the tree, the Document object is the entrance to operate the entire Document.

◆ Element and Attr objects: These node objects are mapped to a certain part of the document. The Node grading level exactly reflects the structure of the document.

◆ Text object: As a subnode of the Element and Attr objects, the Text object expresses the Text content of the Element or attribute. The Text node no longer contains any child nodes.

◆ SET index: DOM provides several set indexes to traverse nodes in the specified mode. Index parameters start from 0.

All nodes in the Html DOM tree are inherited from the Node object. The Node object defines some basic attributes and methods. These methods can be used to traverse the tree. At the same time, the Node name and value can be known and its type can be determined based on the attributes.
With DOM, developers can dynamically create XML, traverse documents, and add/delete/modify documents. The APIS provided by DOM are not related to programming languages. Therefore, for some interfaces that are not clearly defined in DOM standards, different parser implementation methods may also be different. For ease of description, examples in this article use the MSXMLDOM solution and Use VBScript to write code.

2. Structure of the Html DOM tree

After the Document object is created, it can be associated with the XML Document or data island. The data island loading method is to assign the data island ID to the Document Object:

 
 
  1. <XMLIDXMLID=“dsoDetails”src=“Books.xml”></XML> 
  2. Setdoc=dsoDetails.XMLDocument  
  3.  

Document loading is divided into three steps:

1. Use the CreateObject method to create a analyzer instance;

2. Set the async attribute to False to disable asynchronous loading. After the file is loaded, the control will be returned to the calling process. If you want to obtain the file loading status, you can read the readyState attribute value;

3. load the specified document using the load method.

 
 
  1. Setdoc=CreateObject(“Microsoft.XMLDOM”)  
  2. doc.async=False 
  3. doc.load“Books.xml”  

XMLDOM also provides a loadXML method to load the XML string into the Html DOM tree. You only need to use the XML string directly as a parameter of this method.


Related Article

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.