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:
- <XMLIDXMLID=“dsoDetails”src=“Books.xml”></XML>
- Setdoc=dsoDetails.XMLDocument
-
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.
- Setdoc=CreateObject(“Microsoft.XMLDOM”)
- doc.async=False
- 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.