Three different ways to parse XML in Android

Source: Internet
Author: User

Comparison of SAX,DOM,PULL

SAX,DOM,PULL each have their own characteristics, the specific operation of XML how to choose it.

1. Memory Footprint

This is a fundamental issue. Because of the limited performance of Android phones compared to current applications, the memory footprint of programs directly affects the speed at which XML is parsed. At this point,SAXandPull are better suited to Android phone development by parsing them with less memory than the DOM .

2. Programming Method

SAX uses event-driven, which invokes a user-written method when the corresponding event is triggered. In other words, each class of XML is parsed to write a new processing class that is appropriate for the class of XML. This is clearly not a good solution, even though it is excellent at parsing speed. And this,DOM , is the norm for the consortium. So it is known and used by more programmers. So in the development process, there is not much difficulty. Pull is a small, even unknown parser, but by the above introduction and examples, we should be able to see the simplicity of it.

3. Access and Modification

As a result of streaming parsing, this means that they cannot be randomly accessed as a DOM , any one of the nodes in the XML. Also,SAX does not provide an API for adding nodes to the document, nor does it remove and modify the content of the document.

4. How to access

This is the root cause of the speed of their resolution. If SAX and Pull are likened to Islands, soon but in a cursory reading, DOM is a word-reading, slow, but memorable. Also note here thatSAX,Pull parsing is synchronized, where the parser reads it and handles it. The DOM is already parsing the file to allow the user to extract information that is of interest in the XML.

Summary:

For memory footprint, it is recommended that you use SAX or Pull to work. But according to how they work: if you just need information about the last few nodes in the XML, or if you're retrieving XML files repeatedly. So basically there is no difference in performance between the three, but at this point,SAX 's processing class makes the program appear bloated compared to other implementations. So, want to do a high-performance Android software, or to more analysis, choose the right tools to play its role.

Related Article

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.