A comparison of SAX, DOM, and pull
SAX, DOM, pull each have their own characteristics, the specific operation of XML when the choice?
1. Memory consumption
This is a fundamental issue. Because Android phone performance relative to the current application operation is still limited, the memory consumption of the program directly affects the speed of parsing XML. At this point, SAX and pull are more suitable for Android phone development than they use to parse less memory than DOM.
2. Programming method
Sax uses event-driven, which invokes the user-written method when the corresponding event is triggered. That is, each parsing of a class of XML requires a new processing class that is appropriate for that class of XML. This is obviously not a good solution, although it is so good at parsing speed. And this is because DOM is the norm. So it is known and used by more programmers. So in the development process, there is not much difficulty. Although pull belongs to a small, even unknown parser, but through the above introduction and examples, we should be able to see its simplicity.
3. Access and modification
Because of the flow parsing, this means that they cannot be accessed randomly, like DOM, in any of the nodes of the XML. Also, Sax does not provide an API for adding nodes to the document, and there is no way to delete and modify the contents of the document.
4. Access mode
This is the root cause of the speed of their resolution. If sax and pull are likened to Yimushihang, but are quick to read, then the DOM is read verbatim, slowly, but with a photographic memory. It is also important to note that the Sax,pull parsing method is synchronous, that is, where the parser reads, where it is processed. The DOM is the information that the user is interested in extracting the XML after parsing it well.
Summarize:
For memory consumption, it is recommended to use Sax or pull to work. But according to the principle of their work: if only need the last few nodes of XML information, or the occurrence of repeated retrieval of XML files, then basically there is no difference in performance, but at this point, the Sax processing class will make the program appear more bloated than other implementations. So, want to do a high-performance Android software, or more analysis, choose the right tool, to play its role.
This part of the main reference URL: http://book.51cto.com/art/201211/367725.htm
Second, the Android parsing XML of these three ways to summarize
Reference URL: http://www.cnblogs.com/JerryWang1991/archive/2012/02/24/2365507.html
(57) Android Parsing XML summary (SAX, pull, Dom three ways)