Differences and relationships between HTML + DOM and XML + DOM

Source: Internet
Author: User

Like the readers who have read this article, due to their own interests, I have continuously studied Ajax programming. With the development of this field, I have found that the so-called Browser Dom, namely, HTML Dom, is a very noteworthy point. We also talked about Dom level1 when we exchanged views with senior technical personnel. We still lack in-depth and standardized auxiliary books, in addition, searching on the network is rare. Our real idea is that, at work, we don't just go through the tool Library/API's advanced abstract content.

To this end, I plan to open the cloud in this article. If you want to use "dom-script" to do a lot of things, then the topic content will be suitable for you, it can also be used as an introduction to Dom. The topic of this article is why developers think that the "DOM Level 1 Standard Architecture" is crucial and where is its prominent importance, there are also the subtle differences and internal relationships between HTML Dom and xml dom.

The Dom level developed by W3C is divided into two modules: core and HTML. The first major module is the core. The W3C specification describes the core as follows:

"This service is suitable for software developers and web script writers to access and manipulate the parsed HTML and XML content contained in product projects ."
"Sufficicent to allow software developers and web script authora toaccess and mainipulate parsed HTML and XML content inside conformingproducts ."

The second is the HTML module. Its standard description is:

"The features of specific elements in HTML and the right, easy-to-use HTML document operation mechanism for intrusive tasks ."
"Functionality that depends on specific elements defined in HTML"

The above shows the importance of the two. At the same time, the significance of the HTML module is that it solves the problem of backward compatibility, which can provide an appropriate solution in today's Dom Level 1 browsers.

According to this statement, if you still cannot understand the above essentials, we can think that HTML documents can use both core APIs and HTML APIs, while XML documents can only use core APIs. In other words, the overlapping parts of HTML and XML include core APIs, while the HTM lapi cannot be shared. As the name suggests, it is limited to HTML documents. This is a preliminary understanding of core/html.

Understanding Dom Level 1 core

The essence of understanding Dom Level 1 core is to regard core as a document composed of many nodes (nodes). That is to say, there may be a large number of entries in this document structure, each item can be understood as a "Node ". This structure can be discussed in two aspects: 1. Everything is a Node object (nodeobject, flat perspective, flattened view, which is suitable for interfaces under polymorphism ); 2. Each object inherits from the base class node and implements the node interface (from the interface and OO inheritance perspective );

Observe the HTML section:

<Div id = "mydiv"> Hello World </div>

This is a closed Div tag. The following content can be analyzed from the DOM Level 1:

  • The label Div can be used as a "Node object (flattening angle, as described earlier)" or an element object (inherited angle-element inherited from node ).
  • The node property ID can also be used as a "Node object (flat angle)" or an attribute object ATTR. Object (inherited angle-ATTR inherits from node ).
  • The text "Hello World" can also be used as a "Node object (flat angle)". The character string object characterdata object (inherited angle-characterdata inherited from node ), text object (inherited angle-Tex t inherits from characterdata ).

Simply put, everything in Dom 1 core is a node, and nodes and their interfaces can be implemented on each object (from the inheritance perspective ), the node interface can have node attributes and methods. -- This is a prerequisite for our understanding. Then, depending on the specific node type, the interface attributes and methods are different, depending on the Dom's design for the node.

Understanding Dom Level 1 html

We deal with HTML documents in our daily work, which is actually the processing work in the DOM Level 1 HTML module specified by W3C. The features and methods of HTML Dom are not standard DOM implementation. They are designed for HTML and make Dom operations easier. The HTML module is concentrated on the htmlelement interface, that is, the interface implemented by all element-type objects. In terms of the scope discussed in this article, the Participation Form of the htmlelement interface is very similar to that of the above node interface. Once the OO design concept is introduced
Interface object, you can define it as an element. A large number of HTML documents are all elements. Of course, there are htmldocument indicating the document itself and htmlcollection of collection containers.

Therefore, to accurately understand the DOM 1html module, you must understand that its interface is element-based instead of node-based ). In that case, what is the difference between the element method and the Node Method (element V. S node)? How should we define the two? For example, in the context of "element-based", properties ofelements is "attributes" and is not an independent Node object. -- Although an element is a special case of a node from a certain point of view, we can still keep the "Node" statement. A tag is a "Node ". Suppose we want to get
What is the value of the string in the ID attribute, In the DOM 1 core mode,

Myelement. attributes ["ID"]. value; // Attributes provided by the slave node interface

Equals to the following method:

Myelement. getattributes ("ID"); // return the method implemented from the element

However, we only use the DOM 1 HTML method as follows:

Myelement. ID;

In this way, you can get the ID. At this moment, you may think that the XML document itself does not necessarily have the ID attribute by default, because you have the htmlelement. the ID attribute is pre-defined in the API. Of course, every element in HTML has the ID attribute !? -- The meaning here is correct and does not hinder our understanding. Indeed, all HTML elements have an id attribute, regardless of htmldivelement/htmlimageelement /......

Core or HTML module?

In this case, should I use the core API or the HTML module API? For HTML documents, the actual difference between using core or HTML moduel is not big. We didn't emphasize this definition much, so we ignored their slight differences. If we think it is ambiguous, we can further look into their details. I personally think that processing XHTML and using core APIs can better describe the XHTML "X", that is, This html is a standard XML document, in order to distinguish it from the original HTML 4.1 in semantics. But remember, when dealing with a xm l-structured document, it is natural to use
Core. If the r esponsexml result returned after the xhmlhttprequest request is executed, you can only use the core API to process the analysis and cannot use HTML.


Text developers should understand that there are differences and connections between HTML Dom and xml dom. In general, except for the above comparison, it is worth mentioning that HTML can not allow well-form, but XML is not.


By Frank (zhangxin)

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.