Android generates and pull parses XML

1、 Generating XML from a single object

How to generate the following XML?

First define an account class with the attributes ID, name, password and createDate.

After defining this class, you can use XmlSerializer to write XML data. Write a method to save the generated XML in xmlparser_ Account.xml file.

Generate account object, and generate XML for a single object

View saved files

2、 Parse the XML composed of a single object into a single object

The generated xmlparser_ Put the account.xml file under RES / XML / and parse the XML into an account object. Xmlresourceparser is used here. Xmlresourceparser inherits the class of xmlpullparse.

Pull parsing is similar to Sax parsing, and is driven by event driven parsing. When the pull parser begins to parse, it calls its next () method to get the next parsed event (including 4 parsing events: start document, end document, start tag, end tag), here's just Pull analysis.

Print the results directly

The log is as follows

3、 XML groups of individual objects

Like this

The XML group formed by generating a single object group is basically similar to that of a single object XML. A method is written to save the generated XML in the xmlparser_ Accounts.xml file.

Simply generate with a few lines of code

The generated files are as follows

4、 Parsing XML groups of individual objects

Like 2. Parsing XML composed of a single object into a single object, please see 2

5、 Generate an XML group consisting of a single object with an attribute

Similar to the following, the account also contains an attribute value. How to generate it is actually very simple. You can modify it based on the XML group composed of three or a single object

Change place to

6、 Parsing an XML group consisting of a single object with an attribute

Similarly, parsing is similar to parsing the XML group composed of a single object. You can modify the ID part for parsing

Original link of this article: http://www.cnblogs.com/liqw/p/4267461.html

Download address: http://download.csdn.net/detail/lqw770737185/8417583

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>