Detailed explanation of three methods of XML parsing and saving by Android programming
This paper describes three methods of XML parsing and saving by Android programming. Share with you for your reference, as follows:
brief introduction
In Android development, there are three ways to parse XML:
1. Sax event based parser has fast parsing speed and occupies less memory. Ideal for Android mobile devices. 2. DOM is stored in memory in a tree structure, so the retrieval and update efficiency will be higher. However, for very large documents, parsing and loading the whole document will consume resources. 3. Pull event based parser is different from Sax. Pull actively requests the next event, so pull is more practical than Sax in controllability. Pull parser is also used to parse various XML in Android system.
The following implements various parsed classes and engineering structures
This is the XML file id.xml and its corresponding book class that we will parse
Book.Java
The following is the implementation of the XML parsing class
Abstract class is used for inheritance of reading and writing XML files
XMLParseFactory.java
Method implemented with Sax
SAXParserTool.java
Implementation method with pull
PULLParserTool.java
Method implemented with DOM
DOMParserTool.java
This is the implementation of calling various parsing classes
MainActivity.java
Analyze the main layout of the implementation
activity_ main.xml
design sketch
Reference articles https://www.oudahe.com/p/24397/ https://www.oudahe.com/p/24398/
PS: here are some online tools on XML operation for your reference:
Online XML / JSON conversion tool: http://tools.jb51.net/code/xmljson
Format XML online / compress XML online: http://tools.jb51.net/code/xmlformat
XML online compression / formatting tool: http://tools.jb51.net/code/xml_ format_ compress
XML code online formatting and beautification tool: http://tools.jb51.net/code/xmlcodeformat
More readers interested in Android related content can view the special topics of this site: summary of Android operation XML data skills, summary of activity operation skills of Android programming, summary of Android resource operation skills, summary of Android file operation skills, introduction and advanced tutorial of Android development, summary of Android view skills, and Android control usage summary
I hope this article will help you in Android programming.