Android Basics (vi) Network data parsing method

Source: Internet
Author: User
Tags xml parser

There are two most common ways to transfer data over a network: XML and JSON, which explain both types of data parsing.

I. XML data parsing

In Android, the common XML parser is the SAX parser, the DOM parser, and the pull parser, respectively.

(1) Sax parsing

The SAX (simple API-to-XML) parser is an event-based parser whose core is the event-handling pattern, which mainly revolves around event sources and event handlers. When an event source generates an event, the event handler is called to handle the corresponding processing method, and an event can be processed. When the event source invokes a particular method in the event handler, it is also passed to the event handler for the status information of the corresponding event, so that the event handler can determine its behavior based on the event information provided.

The advantage of the SAX parser is that the parsing is fast and consumes less memory. Ideal for use in Android mobile devices.

(2) Dom parsing

The DOM is a collection of tree-based nodes or pieces of information that allow developers to traverse the XML tree using the DOM API and retrieve the data they need. Parsing the structure usually requires loading the entire document and constructing the tree structure before the node information can be retrieved and updated.

Because the DOM is stored in memory in a tree structure, retrieval and update efficiency is higher. But for extremely large documents, parsing and loading the entire document can be resource-intensive.

(3) Pull analysis

The pull parser operates in a similar manner to sax, and is an event-based pattern. The difference is that during pull parsing, we need to get the generated events and do the corresponding operations, instead of executing our code in a way that the processor triggers an event like sax. The pull parser is compact, fast, and easy to use, and is ideal for Android mobile devices, and the pull parser is used to parse various XML inside the Android system.

Android Basics (vi) Network data parsing method

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.