Difference between Pull and SAX parsing and PullSAX Parsing

Source: Internet
Author: User

Difference between Pull and SAX parsing and PullSAX Parsing

The Pull parser and the SAX Parser have differences but similarities. The difference is that the SAX Parser automatically pushes events to the registered event processor for processing, so you cannot control the event processing to take the initiative to end; the Pull parser is used to allow your application code to actively retrieve events from the parser, because it is actively obtaining events, therefore, after meeting the required conditions, you can stop obtaining the event and complete the parsing. This is their main difference.


What is the difference between Dom and SAX in xml parsing?

SAX concepts
SAX is the abbreviation of Simple API for XML. It is not a standard officially proposed by W3C. It can be said that it is a "folk" fact standard. In fact, it is a product of community discussions. Even so, there is no less DOM than the application of SAX in XML, and almost all XML parser will support it.

Compared with DOM, SAX is a lightweight method. We know that when processing the DOM, We need to read the entire XML document, and then create a DOM tree in the memory to generate each Node object on the DOM tree. When the document is small, this will not cause any problems, but once the document is large, it will become quite time-consuming and laborious to process the DOM. In particular, its demand for memory will also multiply, making it uneconomical to use DOM in some applications (such as in the applet ). At this time, a better alternative solution is SAX.

SAX is conceptually different from DOM. First of all, unlike the DOM document driver, it is event-driven, that is, it does not need to read the entire document, and the document reading process is the parsing process of SAX. Event-driven is a program running method based on the callback mechanism. (If you have a clear understanding of the new proxy event model in Java, this mechanism will be easily understood)

When XMLReader accepts XML documents, the XML documents are parsed during reading. That is to say, the process of reading the documents and the process of parsing are performed at the same time, which is very different from the DOM. Before parsing, You need to register a ContentHandler with XMLReader, which is equivalent to an event listener. Many methods are defined in ContentHandler, such as startDocument (), which is customized During the parsing process, something that should be handled at the beginning of the document. When XMLReader reads the appropriate content, it will throw the corresponding event and delegate the event processing permission to ContentHandler, and call the corresponding method to respond.


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.