Apr 19, 2008

XML programming in Java technology, Part 2

In an earlier tutorial ("XML programming in Java technology, Part 1"), 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. This tutorial will look at more difficult things that weren't covered before, such as:
• Getting and setting parser features
• Working with namespaces
• Validating XML documents

As in the introductory tutorial, the APIs I'll cover are:
• 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)

I'll also cover several approaches to validation, including W3C XML Schema, RELAX
NG, and Schematron.

About the examples
Most of the examples here will work with the Shakespearean sonnet that appeared in the last tutorial. The structure of this sonnet is:









[14 elements]




In the various sample programs, some versions of this document will have namespaces, and some will use DTDs, W3C XML Schemas, or other schema languages for validation. For the complete examples, see the following files:
• sonnet.xml
• sonnet.dtd (download to view in a text editor)
sonnetNamespaces.xml
sonnet.xsd
sonnetSchema.xml
sonnet.rng
sonnetRules.xsl
sonnetSchematron.xml
As an alternative, download x-java2_code_files.zip to view these files in a text editor.

Download this tutorial

0 comments: