Three methods for processing XML files (Java)

Source: Internet
Author: User

1 DOM

DOM (Document Object Model) is a Document Object Model. DOM can access and modify the content and structure of a Document in a way independent of platform and language. In other words, this is a common way to represent and process an HTML or XML document. It is very important that DOM is designed based on the specification of Object Management Organization (OMG), so it can be used in any programming language.
DOM is actually a document model described in an object-oriented way. DOM defines the objects required to represent and modify documents, the behavior and attributes of these objects, and the relationship between these objects. DOM can be considered as a tree representation of data and structure on the page, but the page may not be implemented in this way.
A good Java open-source implementation in this way is jsoup.

2 SAX
An event-driven API is used as a stream Parser by a Parser (that is, a "SAX Parser. By
The user-defined callback function is called if an event occurs during parsing. SAX events include:
XML text node
XML Element Node
XML processing commands
XML Annotation
Events are triggered when any XML feature is encountered, and when they are ended, they are triggered again. XML attributes are also part of the data transmitted to element events. The direction of data processing in SAX is single; the parsed data cannot be read again without restarting.

3 JAXB

Java Architecture for XML Binding is an industry standard and a technology that can generate Java classes based on XML Schema. In this process, JAXB also provides a way to reverse generate a Java object tree for the XML instance document, and re-write the content of the Java object tree to the XML instance document. On the other hand, JAXB provides a fast and easy way to bind the XML schema to the Java representation, so that Java developers can easily combine XML data and processing functions in Java applications.


Object <--> XML Tool

 

This means that you can use the flexibility of the platform's core XML data in Java applications without processing or even knowing XML programming skills.
. Furthermore, you can take full advantage of XML without relying on complex XML processing models such as SAX or DOM. JAXB hides the details and removes the useless relationship between SAX and DOM. The generated JAXB class only describes the relationships defined in the original model. The result is a combination of Highly portable Java code and highly portable XML data. These codes can be used to create flexible and lightweight applications and Web services.

JAXB is just a standard. The toolkit provided by Sun can only be said to be a relationship between the Implementation Schema and XML documents, just like the relationship between classes and instances in Java.

 

 


Author: hongchangfirst

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.