When developing using the Java language, XML files are always used to transmit data. Therefore, XML parsing problems are always encountered, especially for Android development and web development. There are three methods to parse XML files: Dom, push, and pull.
- DOM method-dom is short for Document Object Model, that is, Document Object Model. It defines a set of language platform-independent interfaces for accessing and operating the structure content of a general document. Dom represents a document with a Node object as the node tree. Because XML documents are structured in a tree, Dom can be used to parse XML. Dom parsing converts the entire XML file into a tree with the Node object as the node to access and operate the document.
The DOM method can operate documents completely and access documents randomly. This is its advantage. But because it needs to read the entire document into a tree, it consumes a lot of memory. This method is often used to see and operate the entire structure of the document in the program.
- Push method -- the push processor generates synchronization events when a document is processed. These events can be processed by an application using a callback handle. This method is suitable for quickly traversing a document to check its validity or retrieve the document content.
- Pull Method -- events are generated from pull in the document under application control. That is to say, the entire parsing process is controlled by the application. This method is most suitable for parsing documents that are obtained from network streams connected to the network.
For these methods, Apis encapsulated in Java can be directly used.
For Dom parsing, refer to core Java volume 2, Chapter 12. For these methods, refer to pro XML development with Java technology.
For general XML parsing, the pull method is recommended because it gives control of the document parsing process to the application, so it is more convenient to control the parsing process.