XML Parser--sax

Source: Internet
Author: User
Tags xml parser

2.Simple API for XML (SAX) the parser :

SAXInterpreter,It can be said that a programming model that leaves the explanation work to the programmer and leaves it to itself.it did not giveDOMthat put the wholeXMLthe document is loaded into memory but is interpreted row by line. then notify the program via event,These notifications are used by specific programs,and then deal with it.,It's like writing event-driven code here..Thus, the memory occupancy rate and the efficiency of interpretation, SAXit has its applicability..

SAXThe events mainly include:
1.the beginning of the documentstartdocumentEvents
2.for an elementstartelementand theendElement
3.for processing character literals, thecharactersEvents
4.and the end of the documentenddocmentEvents



2)SAX

The advantages of SAX processing are very similar to the advantages of streaming media. The analysis can begin immediately, rather than waiting for all data to be processed. Also, because the application examines data only when it is being read, it does not need to store the data in memory. This is a huge advantage for large documents. In fact, the application doesn't even have to parse the entire document; it can stop parsing when a condition is met. In general,SAX is much faster than its surrogate DOM .  

Select DOM or choose SAX? For developers who need to write their own code to handle XML documents, choose DOM or SAX  The analytic model is a very important design decision. DOM uses a tree-structured approach to accessing XML documents, and The event model that SAX uses.  

The DOM parser transforms an XML document into a tree containing its contents and can traverse the tree. The advantage of parsing a model with DOM is that programming is easy, and developers simply need to invoke the build instructions and then use the navigation APIs to access the desired tree nodes to complete the task. It is easy to add and modify elements in the tree. However, because of the need to process the entire XML document when using the DOM parser , the performance and memory requirements are high, especially when you encounter large XML file at the time. Because of its traversal capabilities,DOM parsers are often used in services where XML documents require frequent changes.

The SAX parser uses an event-based model that can trigger a sequence of events when parsing an XML document, and It can activate a callback method when a given tag is found. Tell the method to make the label that was found. SAX requirements for memory are usually low because it allows the developer to decide for themselves which tag to process . especially if the developer only needs to work with some of the data contained in the document, SAX This ability to expand has been better reflected. But it is difficult to code with a SAX parser, and it is difficult to access multiple different data in the same document at the same time.


XML Parser--sax

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.