Java Reference
In-Depth Information
Chapter 17: The XML Document Object Model and
JDBC
In This Chapter
XML is fast becoming a universal standard for exchanging data between applications. Today, many
major organizations are using XML in the daily course of business. The International Press
Telecommunications Council, for example, has defined an XML DTD to simplify news distribution and
publishing. Even local phone companies are using XML as the basis of a computerized order placement
and billing system.
This means that XML processing is steadily becoming more and more important to Java programmers.
Typically XML documents are used as a means of transferring database records between businesses.
This chapter starts with a brief introduction to XML, and then goes on to discuss how to generate XML
documents from a SQL query, and how to populate a database from an XML document.
XML versus HTML
The eXtensible Markup Language (XML) is a text-based markup language that is fast becoming a
standard for data interchange both on the Web and between applications. XML is similar to the
HyperText Markup Language (HTML) in that it uses tags enclosed in angle brackets (<>) to identify data,
as shown in Listing 17-1 .
Listing 17-1: XML example
<?xml version="1.0"? >
<CONTACT_INFO>
<FIRST_NAME>Vito</FIRST_NAME>
<LAST_NAME>Corleone</LAST_NAME>
<STREET>123 Main</STREET>
<CITY>New York</ CITY >
<STATE>NY</STATE>
<ZIP>12345</ZIP>
</CONTACT_INFO>
Unlike HTML tags, XML tags identify and describe data rather than specifying how to display it. The
tags used to identify and describe data are application dependent, so you can use any tags you like, as
long as they follow the rules the W3C XML standard defines.
A major difference between XML and HTML is that an XML document must always be well formed.
Among other things, this means that every tag has a closing tag. For example, in HTML, you frequently
see dangling paragraph <P> and break <BR> tags. These are illegal in XML, which requires that a
closing tag be provided, either by using the form <P></P> or <P/> .
Another frequent usage in HTML, but illegal in XML, is incorrect nesting. Most browsers can handle
HTML with elements closed in arbitrary order, as in the following example, which combines incorrectly
closed elements with elements that simply aren't closed at all. This example displays just fine in a
browser but is unreadable as XML:
<HTML>
<BODY>
<CENTER><FONT FACE="Arial">
Hello World
Search WWH ::




Custom Search