 | Level: Introductory Doug Tidwell (dtidwell@us.ibm.com), XML Evangelist, IBM
09 Jul 2004 In an earlier tutorial, Doug Tidwell looked at the basics of XML parsing in the Java language. He 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. In this tutorial, he looks at more difficult things that weren't covered in Part 1, such as working with namespaces, validating XML documents, building XML structures without a typical XML document, converting between one API and another, and manipulating tree structures. He also shows you some of the more esoteric features of DOM, SAX, JDOM, and JAXP.
Prerequisites
This tutorial assumes that you know how to compile and run a Java program, and that you know how to set your CLASSPATH variable. This tutorial covers these APIs:
- The Document Object Model (DOM), Levels 1, 2, and 3
- The Simple API for XML (SAX), Version 2.0
- JDOM, a simple Java API created by Jason Hunter and Brett McLaughlin
- The Java API for XML Processing (JAXP)
It discusses the following approaches to validation are discussed W3C XML Schema, RELAX NG, and Schematron.
System requirements
You will need JavaScript enabled in your browser. To run the examples, set up your machine as follows:
- Download the Xerces XML parser at the Apache XML Project (http://xml.apache.org/xerces2-j/) or directly from the download page (http://xml.apache.org/xerces2-j/download.cgi).
- Unzip the downloaded file from Apache to create 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.
- Download the latest version of JDOM from the JDOM project's Web site (http://jdom.org/).
- Unzip the file downloaded from JDOM to create a directory named jdom-b9 (or something similar). The JAR file you need (jdom.jar) should be in the build directory.
- Finally, download the zip file of examples (x-java2_code_files.zip) for this tutorial and unzip the file.
- Add the current directory (.), xercesImpl.jar, xml-apis.jar, and jdom.jar to your CLASSPATH.
Other tutorials in this series are:
Duration
Under two hours
Formats html, pdf
|  | |  |