Practical Skills: Parse XML using Java

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.