The Wayback Machine - https://web.archive.org/web/20120626014159/http://www.ibm.com:80/developerworks/xml/tutorials/x-java3/
Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

XML programming in Java technology, Part 3

Doug Tidwell, XML Evangelist, EMC
Author photo

In a multicenter, double-blind clinical test, Doug Tidwell was shown to provide significant relief from seasonal allergy symptoms caused by programming with XML and Java technologies.

Also available is slow-acting Doug Tidwell (Doug Tidwell SA), which delivers a consistent dose of medication for up to 24 hours. Side effects of Doug Tidwell were generally mild and included dizziness, moderate to severe nausea, numbness in the extremities, and, in rare cases, paralysis and death.

Ask your doctor if Doug Tidwell is right for you.

For further details, consult Doug's blog.

Summary:  This advanced tutorial covers more sophisticated topics for manipulating XML documents with Java technology. Author Doug Tidwell shows you how to do tasks such as generate XML data structures, manipulate those structures, and interface XML parsers with non-XML data sources. As you'd expect, all of the examples are based on open standards.

Date:  16 Jul 2004
Level:  Introductory PDF:  A4 and Letter (119 KB | 35 pages)Get Adobe® Reader®

Activity:  8425 views
Comments:  

Introduction

About this tutorial

In an earlier tutorial, I showed you the basics of XML parsing in the Java language. I covered the major APIs (DOM, SAX, and JDOM), and went through a number of examples that demonstrated the basic tasks common to most XML applications. The second tutorial in the series covered parser features, namespaces, and XML validation. This final tutorial looks at more difficult things that I didn't cover before, such as:

  • Building XML structures without an XML document
  • Converting between one API and another (SAX events to DOM trees, for example)
  • Manipulating tree structures

Programming interfaces

As in the previous tutorials, I cover these APIs:

  • The Document Object Model (DOM), Levels 1, 2, and 3
  • The Simple API for XML (SAX), Version 2.0
  • JDOM

Although many of the sample programs I discuss here use JAXP (the Java API for XML parsing), I won't discuss JAXP specifically in this tutorial.


About the examples

Most of the examples here work with the Shakespearean sonnet that appeared in the previous tutorials. The structure of this sonnet is:

<sonnet>
  <author>
    <lastName>
    <firstName>
    <nationality>
    <yearOfBirth>
    <yearOfDeath>
  </author>
  <lines>
    [14 <line> elements]
  </lines>
</sonnet>
          

I'll use this sample document throughout this tutorial. Links to the complete set of sample files are shown below:

As an alternative, you can download x-java3_codefiles.zip to view these files in a text editor.

In addition to the sonnet, you'll also learn how to parse files of comma-separated values and text strings, including several approaches to converting that information into XML or XML data structures.


Setting up your machine

You'll need to set up a few things on your machine before you can run the examples. (I'm assuming that you know how to compile and run a Java program, and that you know how to set your CLASSPATH variable.)

  1. First, visit the home page of the Xerces XML parser at 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).
  2. Unzip the file that you downloaded from Apache. This creates a directory named xerces-2_5_0 or something similar, depending on the release level of the parser. The JAR files you need ( xercesImpl.jar and xml-apis.jar ) should be in the Xerces root directory.
  3. Visit the JDOM project's Web site and download the latest version of JDOM (http://jdom.org/).
  4. Unzip the file you unloaded from JDOM. This creates a directory named jdom-b9 or something similar. The JAR file you need ( jdom.jar ) should be in the build directory.
  5. Finally, download the zip file of examples for this tutorial, x-java3_codefiles.zip, and unzip the file.
  6. Add the current directory (. ), xercesImpl.jar, xml-apis.jar, and jdom.jar to your CLASSPATH.

1 of 10 | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=XML
ArticleID=138319
TutorialTitle=XML programming in Java technology, Part 3
publish-date=07162004
author1-email=
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Special offers

Morty Proxy This is a proxified and sanitized view of the page, visit original site.