Learn Together-dom Overview

Source: Internet
Author: User

What is Dom?

DOM: Document Object Model (Document Object Model) is a standard programming interface recommended by W3C for processing Extensible slogans. The history of the Document Object Model can be traced back to the "browser war" between Microsoft and Netscape in the late 1990 s. The two sides decided to survive and survive JavaScript and JScript, so they granted powerful functions to the browser on a large scale. Microsoft has added a lot of exclusive items in Webpage technology, including VBScript, ActiveX, and Microsoft's own DHTML format, which makes it impossible for many webpages to be displayed normally on non-Microsoft platforms and browsers. Dom is a masterpiece developed at that time. Please refer to Baidu encyclopedia http://baike.baidu.com/view/14806.htm for details

What is the use of Dom?

Dom is used to encapsulate markup documents (such as HTML and XML) into objects and encapsulate all content (such as tags, text, and attributes) in markup documents into objects. The object is encapsulated to facilitate operations on these documents and all the content in the document. Because of the appearance of objects, attributes and behaviors can be called.

Document Object Model

Document: markup document (HTML, XML ).

Object: an instance that encapsulates attributes and behaviors and can be called directly.

Model: All markup documents share some common characteristics.

After introducing Dom, let's talk about itsWorking PrincipleRight!

How does Dom perform operations on markup documents?

To operate a markup document, you must first parse it. Next let's take a look at the figure of the DOM parsing process,


From this figure, we can see that the DOM parsing method is to parse the markup document into a DOM tree and encapsulate the content in the tree into a Node object. This is completely an object-oriented design method.
All objects!

I have to boast the foresight of my predecessors.

Everything has two sides, and DOM technology is no exception.

Benefits: You can perform any operations on nodes in the tree, such as adding, deleting, modifying, and querying nodes)

Disadvantages: This resolution method loads the entire Tag file into the memory, which means that if the size of the Tag file is too large, the memory space is wasted.

Now, the powerful predecessors have made new moves!

As the saying goes, some civil organizations have defined a method called sax parsing,

What is sax?

This is an event-driven "push" model. Although it is not a W3C standard, it is a widely recognized API. Unlike Dom, The SAX Parser creates a complete document tree. Instead, it activates a series of events when reading documents, which are pushed to the event processor, the event processor then provides access to the document content.

Comparison between Sax and Dom

Compared with Dom, The SAX Parser provides better performance advantages and provides effective low-level access to XML document content. The biggest advantage of the sax model is the low memory consumption, because the entire document does not need to be loaded into the memory at a time, which allows the SAX Parser to parse documents larger than the system memory. In addition, you do not need to create objects for all nodes as in the Dom. Finally, the sax "push" model can be used in the broadcast environment. It can register multiple contenthandler at the same time and receive events in parallel, instead of processing events one by one in one pipeline.

Sax Defects

The disadvantage of Sax is that you must implement multiple event handlers to be able to process all incoming events, and you must maintain the event status in the application code, because the SAX Parser cannot exchange metadata, such as the DOM parent/child support, you must track the position of the parser at the document level. In this way, the more complex your documents are, the more complicated your application logic is. Although it is not necessary to load the entire document to the memory at a time, the SAX Parser still needs to parse the entire document, just like the Dom.

We do not want to detail the analysis when we learn the XML in the future.

Three Dom modes:

Dom1: Encapsulate HTML documents into objects.

Dom2: Added some new features, such as parsing namespaces.

What isNamespaceWhat about it? Don't worry, I will give you a detailed explanation:

When a tag with the same name appears, it indicates that the meaning of the tag is different and is prone to conflict. In this case, we can define a tag with the same name and meaning in different storage. This is equivalent to two Java classes with the same name. class needs to be placed in two different packages.

The syntax is as follows. No table label is defined and a namespace is defined.

<HTML xmlns = "A">

<Table> </table>

</Html>

<HTML xmlns = "B">

<Table> </table>

</Html>

Dom3: Encapsulate XML documents into objects.

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.