Method of parsing XML file in Android system

Preface when learning the framework layer source code of Android, Android uses xmlpullparser to parse the source code of XML files. Therefore, the use of xmlpullparser is also introduced here.

The Chinese name of XML (Extensible Markup Language) is extensible markup language. Tags refer to information symbols that can be understood by computers. Through this tag, computers can process articles containing various information. Usage XML design uses to transmit and carry data information without representing or displaying data, while HTML language uses to represent data, so the focus of XML usage is to explain what data is and carry data information.

Structure each XML document starts with the XML preamble. In the previous code, the first line is the XML preamble, <? xml version="1.0"?>。 This line of code will tell the parser or browser that the file should be parsed according to XML rules. However, the name of the root element is defined by the document type or XML schema.

Xmlpullparser pull parsing XML is to parse XML files in an event driven manner. When pull starts parsing, we can first obtain the current parsing event type through the geteventtype() method and the next parsing event type through the next() method. The pull parser provides start_ Document, end_ Document, start_ Tag, end_ Tag (end tag) four event resolution types. When you are in an element, you can call getattributevalue() method to get the value of the attribute, or you can get the text value of this node through nexttext(). The following is an example to analyze. The XML sample file code that needs to be parsed is as follows:

Xmlpullparser parser

The definition of the collage class is relatively simple, and the code is as follows:

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