Transfer from http://blog.csdn.net/sam_zhang1984
There are two ways of parsing XML: SAX and DOM. They all have pros and cons.
The DOM is to load all the XML documents into memory and then treat them as a tree. The advantage is that it is more convenient to deal with trees, but the disadvantage is that if the XML file is larger, it will consume a large amount of memory;
SAX is a progressive scan of an XML document, line-by-row parsing, and can be processed in the process of XML documents at any point in time to abort the processing process, such as to find our target node, the remaining XML document content can not read, the direct end. The disadvantage is that the operation is relatively inconvenient, and the XML document processing, if modified, add, delete and other operations more inconvenient.
SAX is a standard interface for event-driven XML parsing. It works by reading the beginning and end of the document, the beginning and end of the tag element, the content entity, and so on, triggering the corresponding function, and we can do the processing we want to do in the corresponding function.
XML parsing mainly requires the following steps:
1. Create an event handler
2. Create a SAX parser
3. Assigning an event handler to a parser
4. Parse the document and send each event to the handler.
Android Learning Note--xml