(Transferred from: http://wenku.baidu.com/view/af39b3164431b90d6c85c72f.html)
Eight, the seventh day of Android learning--xml file parsing method
XML file: Extensible Markup Language
Definition: Used to mark electronic files with a structured markup language that can be used to tag data, define data types, and is a source language that allows users to define their own markup language.
How to parse xml:
- Sax--simple API for XML is both an interface and a package
It uses event-driven, which parses an XML document and needs to parse the entire document, and during parsing, it determines whether the current character parsed matches a part of the XML, and if so, triggers the event if it does not, triggering the corresponding callback function if it does not conform. This callback function is encapsulated in the ContentHandler interface: Because ContentHandler is implemented will be forced to implement a lot of useless methods, so do not use this interface, we inherit the DefaultHandler class, because it implements the ContentHandler part of the method we need, save some of our useless methods oh. So choose to use this.
The downside is that it can be laborious to use it to add or remove some content.
- Dom--document Object Model
This parsing method is to load a known XML document into memory and store it as a DOM tree, parsing the file based on the relationship between the DOM node and the child nodes, and if the file is too large, parsing can be time-consuming and resource-intensive.
Here are the main explanations for the process of Sax parsing XML files:
(i) Creating an event handler
(ii) Creating a SAX parser
(iii) Assigning an event handler to a parser
(iv) parsing the document and sending each event to the handler
Eight, the seventh day of Android learning--xml file parsing method (GO)