Use JAVA technology for XML programming (part 1)

Source: Internet
Author: User
Tags object model xml parser
In the past few years, XML has become a common data format. This revised tutorial will introduce you to the most common programming interfaces for processing XML documents in Java.
The most common XML processing job is to parse XML documents. Parsing includes reading the XML document and determining its structure and content. One advantage of XML programming is that you can use an open-source, free XML parser to read XML documents. This tutorial describes how to create a parser object, request the parser to process XML files, and process the parsing results. As expected, you can use different methods to complete such common tasks. I will analyze the standards involved and when to use this or that method.
2nd pages of programming interfaces (5 pages in total)
To simplify the compilation of Java programs for processing XML, multiple programming interfaces have been established. These interfaces can be defined by the company or by a standard body or user group to meet the needs of XML programmers. This tutorial will discuss the following interfaces:
Document Object Model (DOM, Document Object Model), Level 2
Simple API for XML (SAX), Version 2.0
A simple Java API created by JDOM, Jason Hunter, and Brett McLaughlin
Java API for XML Processing (JAXP)
The first three interfaces (DOM, SAX, and JDOM) define how to access and represent the content of an XML document. JAXP contains classes for creating parser objects. To create a DOM or SAX parser, you must use JAXP. If you use JDOM, the JDOM library will use JAXP to create a parser for you. In short:
Use DOM, SAX, or JDOM to process the content of an XML document.
If DOM or SAX is used, JAXP is used to create a parser.
If JDOM is used, the JDOM library creates a parser for you.
I will examine the design objectives, strengths, and weaknesses of each of the above APIs, as well as their history and the standard bodies for creating these APIs.
Example Page 1 (5 pages in total)
This tutorial contains multiple sample programs that use DOM, SAX, and JDOM APIs. All these programs use the fourteen lines of Shakespeare's poems marked in XML. The structure of the fourteen lines of poetry is as follows:
<Sonnet>
<Author>
<LastName>
<FirstName>
<Nationality>
<YearOfBirth>
<YearOfDeath>
</Author>
<Lines>
[14 <line> elements]
</Lines>
</Sonnet> for a complete example, see and (view it in a text editor after download ). Before running these examples, you must set your machine. (Assume that you know how to compile and run Java programs and how to set CLASSPATH variables .) First visit the Xerces XML parser home page on the Apache XML Project (http://xml.apache.org/xerces2-j. You can also go directly to the download page (http://xml.apache.org/xerces2-j/download.cgi ).

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.