Apr 19, 2008

XML programming in Java technology, Part 1

About this tutorial

Over the last few years, XML has become a universal data format. In this updated tutorial, I'll show you the most common programming interfaces for working with XML documents in the Java language. The most common XML processing task is parsing an XML document. Parsing involves reading an XML document to determine its structure and contents. One of the pleasures of XML programming is the availability of open-source, no-cost XML parsers that read XML documents for you. This tutorial focuses on creating parser objects, asking those parsers to process XML files, and handling the results. As you might expect, you can do these common tasks in several different ways; I'll examine the standards involved as well as when you should use one approach or another.

Programming interfaces
A number of programming interfaces have been created to simplify writing Java programs that process XML. These interfaces have been defined by companies, by standards bodies, and by user groups to meet the needs of XML programmers. In this tutorial, I'll cover the following interfaces:
• The Document Object Model (DOM), Level 2
• 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)

The first three of these four interfaces (DOM, SAX, and JDOM) define how the
contents of an XML document are accessed and represented. JAXP contains classes for creating parser objects. To create DOM or SAX parsers, you'll use JAXP. When you use JDOM, the JDOM library uses JAXP under the covers to create a parser. To sum it all up:
• You use DOM, SAX, or JDOM to work with the contents of an XML document.
• If you use DOM or SAX, you use JAXP to create a parser.
• If you use JDOM, the JDOM library creates a parser for you.

I'll explore the design goals, strengths, and weaknesses of each of these APIs, along
with a bit of their histories and the standards bodies that created them.

Download this tutorial

0 comments: