Summary of several methods of Android operating XML

As a recognized data exchange format in the industry, XML is widely used and implemented on various platforms and languages. Its standard type, reliability, safety... No doubt. On Android platform, if we want to realize data storage and data exchange, we often use XML data format and XML file.

Tip: there are several types of data stored in Android: SharedPreferences (parameterization), XML files, sqllite databases, networks, ContentProviders, etc.

In Android, there are generally several ways to operate XML files: sax operation, pull operation, DOM operation, etc. The DOM method is probably the most familiar and conforms to the W3C standard.

1)

In the Java platform, there are excellent open source packages such as Dom4j, which is very convenient for everyone to use the DOM standard to operate XML files. In JavaScript, DOM parsing and operation are slightly different for different browser parsing engines (but this is not the focus of this chapter). The DOM method also has its disadvantages. Usually, the XML file is loaded at one time and then parsed using the DOM API, which consumes a lot of memory and has a certain impact on the performance. Although the configuration of our Android phones is constantly upgraded, the memory is not comparable with the traditional PC for the time being. Therefore, it is not recommended to use DOM to parse and manipulate XML on Android.

Sax (simple API for XML) is a widely used XML parsing standard. It usually uses the handler mode to process XML documents. This processing mode is very different from our usual way of understanding. Some friends often find it difficult to understand when they first contact Sax. In fact, Sax is not complicated, but just a different way of thinking. As its name indicates, in order to let us process XML documents in a simpler way, let's start now.

Pull parsing is very similar to Sax parsing. Both are lightweight parsing. Pull has been embedded in the Android kernel, so we don't need to add a third-party jar package to support pull. The differences between pull parsing and sax parsing are (1) pull triggers the corresponding event after reading the XML file, and the calling method returns the number (2) pull can control where it wants to be parsed in the program and stop parsing.

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