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