Comparison of--xml analytic methods of "Java Technology drip"

Source: Internet
Author: User
Tags xpath

Why?

" It can be used to tag data, define data types, and is a source language that allows users to define their own markup language. It is ideal for world Wide Web transport, providing a unified approach to describing and exchanging structured data that is independent of the application or vendor. is a cross-platform, content-dependent technology in the Internet environment and an effective tool for dealing with distributed structure information today. "XML is designed to transmit and store data;

his platform-independent, language-independent, system-independent, to the data inheritance and interaction brought great convenience. It is therefore increasingly common to use XML.

Way

1.dom--documentobject Model

like Operation HTML, the use of Dom has been studied in JS, is recommended by the organization of the Extensible Flag Language Processing standard programming interface. The DOM parser transforms the XML document into a tree structure and can traverse the tree.

Pros: Easy to operate, developers only need to invoke the build instructions, the entire document tree in memory, and then use Navigationapis To delete, modify, rearrange and more.

disadvantage: Load the entire document into memory, consuming resources (time and space). the XML document will be read into memory directly, and then parsed, if the file is large, the content needs to be read more and less efficient.

applications: One-time parsing requires multiple accesses to the XML document data, sufficient hardware resources (memory, CPU).

2.sax--simpleapi for XML

Sax is based on event flow parsing, one for handling XML Event-driven "push" model, similar to the media flow, the SAX parser can start a series of events when parsing XML, and the developer writes the response event code to save the data.

Pros: resolves the dom loading of large files is a resource-intensive issue

Shortcomings, it is the characteristics of his shortcomings, you must implement multiple event handlers to handle all the arrival time, logical processing is more complex.

3.jdom--javadocument Object Model

As the name implies: The Java-specific document model, which uses the 28 law principle, greatly reduces the amount of code, effectively combining the functions of sax and DOM. The underlying is still implemented using DOM, sax.

4.dom4j

dom4j is an easy-to-use, open-source library for Xml,xpath and XSLT. It is applied to the Java platform, uses the Java Collection framework, and fully supports Dom,sax and JAXP.

the project simply tried the application dom4j parse the XML in a way that reads the following general steps:


Sax reads Saxreader reader = new Saxreader (),//Gets the current thread through thread, obtains loader classloader,getresource ... (Load by Resource) gets the input stream inputstream in = Thread.CurrentThread (). Getcontextclassloader (). getResourceAsStream ("Resource relative path");D Ocument DC = Reader.read (in),//Gets the element elementelement Drivernameelt = (Element) by XPath ("Dc.selectobject /driver-name ");


Summarize

DOM and Sax are two of the more basic parsing XML , while the other two are DOM with the SAX further encapsulation of the.

more and more realize that the importance of XML, to achieve system flexibility, configuration files are really everywhere, the operation of the XML is not familiar with, today summed up the Java operation of the XML in several ways, but also hope that in the later learning applications more proficient and profound.

Resources:

four operations in Java ( DOM, SAX, JDOM, dom4j) XML in a detailed and comparative way

detailed four ways to parse XML in Java

Java parsing XML a few ways

http://www.w3.org/

Comparison of--xml analytic methods of "Java Technology drip"

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.