XML Programming with Java Technology (Part One)

Source: Internet
Author: User
Tags contains object model xml parser root directory
Xml| programming in the past few years, XML has become a common data format. This revised tutorial will introduce you to the most commonly used programming interfaces in the Java language for processing XML documents.

The most common XML processing work is parsing XML documents. Parsing involves reading an XML document and determining its structure and content. An advantage of XML programming is that you can read XML documents using an open source, free XML parser. This tutorial focuses on creating parser objects, requiring parsers to process XML files, and handling parsing results. As you might expect, these common tasks can be done in different ways, and I will analyze the standards involved and when to use this or that approach.

Programming Interface page 2nd (total 5 pages)


To simplify writing Java programs that process XML, a variety of programming interfaces have been established. These interfaces are either defined by the company or defined by a standard body or user group to meet the needs of the XML programmer. The following interfaces are discussed in this tutorial:

Document Object Model (DOM, Document object models), Level 2
Simple APIs for XML (SAX), Version 2.0
JDOM, a simple Java API created by Jason Hunter and Brett McLaughlin
Java API for XML processing (JAXP)
The first three of these four interfaces (DOM, SAX, and JDOM) define how to access and represent the content of an XML document. JAXP contains the class that creates the parser object. To create a DOM or SAX parser, you need to use JAXP. If using the Jdom,jdom library will use JAXP behind the scenes to create a parser for you. Anyway:

Use DOM, SAX, or JDOM to work with the contents of an XML document.
If you use DOM or SAX, use JAXP to create the parser.
If you use JDOM, the JDOM library creates a parser for you.
I will look at the design goals, strengths, and weaknesses of each of these APIs, as well as a bit of their history and the standard body for creating these APIs.

About the example page 3rd (total 5 pages)


This tutorial contains several sample programs that use the DOM, SAX, and JDOM APIs. All of these programs use XML-tagged Shakespeare 14 lines of verse. The structure of the 14 lines of verse is as follows:

<sonnet>
<author>
<lastName>
<firstName>
<nationality>
<yearOfBirth>
<yearOfDeath>
</author>
<lines>
[<line> elements]
</lines>
</sonnet> complete examples See and (Use a text editor to view after downloading). Set up the machine before running these examples, you need to make some settings for your machine. (Suppose you know how to compile and run Java programs, and learn how to set up CLASSPATH variables.) First, visit the Xerces XML Parser home page on 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). Unzip the files downloaded from Apache. This will create a directory named Xerces-2_5_0 or a similar name, depending on the version of the parser. The required JAR files (Xercesimpl.jar and Xml-apis.jar) should appear in the Xerces root directory. Visit the JDOM Project site and download the latest version of JDOM (http://jdom.org/). Unzip the files downloaded from the JDOM, which will create a directory named JDOM-B9 or a similar name. The desired JAR file (Jdom.jar) should be in the build directory. Finally, download the sample zip file for this tutorial and extract the file. Add the current directory (.), Xercesimpl.jar, Xml-apis.jar, and Jdom.jar to the CLASSPATH variable. The underlying XML parser is a piece of code that reads an XML document and analyzes its structure. This section describes how the XML parser works. I'll discuss different types of XML parsers and when to use them. Later chapters of this tutorial discuss how to create a parser and how to handle the results given by the parser. How to use the Parser page 2nd (total 12 pages) I'll discuss this in more detail in later chapters, and in general, using parsers requires the following steps: Creating a parser object so that the parser points to your XML document processing results Obviously the third step is the most complex. Once you know the contents of an XML document, for example, you might want to generate a Web page, create an order, or make a pie chart. Given the diversity of data contained in XML documents, it is a daunting task to write an application to handle all possible inputs. Fortunately, the common XML parsing tools discussed here make this work much simpler.



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.