Comparison of XML parsing methods for Java processing

Source: Internet
Author: User
Tags xpath

Many people cannot figure out the differences between Java and XML parsing methods. The following will be explained by an authoritative instructor trained by Dana technology Java.
(1) Dom
Advantages and disadvantages: W3C standards are implemented and there are many Programming Language This resolution method is supported, and the operation is simple and quick, Which is easy for beginners to master. The processing method is to read XML into the memory as a tree structure for operation and parsing. Therefore, it supports applications. Program Modify the content and structure of XML data, but at the same time, because it needs to read the entire XML file into the memory for analysis at the beginning of processing, therefore, when parsing XML files with large amounts of data, it may encounter risks similar to memory leaks and program crashes. Please pay attention to this.
Applicability: small XML file parsing, full parsing, or most XML parsing, XML tree content needs to be modified to generate its own object model
(2) Sax
Sax fundamentally solves the problem that Dom occupies a large amount of resources when parsing XML documents. The implementation is to read the entire XML document tree through a technology similar to stream parsing, and respond to the needs of programmers for XML data parsing through an event processor. Because it does not need to read the entire XML file into the memory, it is very obvious to save system resources, it plays an important role in some cases where large XML documents need to be processed and high performance requirements are required. The support for xpath query of sax makes developers more flexible and easier to process XML. However, at the same time, there are still some shortcomings that plague the majority of developers: first, it is very complicated
The API interface is daunting. Because it is a file scanning method similar to stream parsing, modification to the XML tree content structure by applications is not supported, which may cause inconvenience.
Applicability: Large XML file parsing, partial parsing, or partial XML tree content, XPath query, and specific XML tree object model generation.
(3) digester/jaxb
Advantages and disadvantages: it is a tool class derived from the above two, in order to meet the special requirements for converting XML into JavaBean, so there is no obvious advantages and disadvantages. As the well-known open-source framework struts XML parsing tool digester, we provide a reliable method to convert XML into JavaBean.
Applicability: You need to directly convert an XML document to a JavaBean file.

 

Original article link: http://www.yctarena.com/javajswz/20130325/3348.html

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.