Example of using pull to parse XML format data in Android App

Pull parses XML files in roughly the same way as sax parses XML files. They are both event driven. Therefore, using pull to parse XML files requires the following steps:

1) Get the xmlpullparser object through the xmlpullparserfactory.

2) Set the input stream through the xmlpullparser object.

3) Continue to parse the XML file through parser. Next() until the end of the file.

The following methods are often needed: xmlpullparserfactory. Newinstance () factory. Newpullparser () parser. Setinput () parser. Next()

The following describes the above steps through an example:

Printed objects:

Pull integrates this parsing in Android, and its performance is similar to that of Sax. Personally, I think it is much easier to use it than Sax parsing; Event driven analysis is adopted. DOM (document object model): a method of parsing XML recommended by W3C organization; Generally, you can only parse small XML files; Because DOM parsing puts the whole XML into memory, which takes up a lot of memory, but it is easy to add, delete, change and check the label glue of the document. Sax (simple API for XML) is not an official standard, but it is the de facto standard of the XML community. Almost all XML parsers support it. Sax parsing is generally suitable for reading XML. Sax parsing reads from top to bottom, line by line.

Take a complete example:

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
分享
二维码
< <上一篇
下一篇>>