16.1 What Is XML?

XML is a close cousin to HTML, but while HTML is primarily concerned with formatting and displaying data, XML is concerned with the data itself. Unlike HTML, with XML you may create your own tags, which is why XML is perfectly suited for describing data. The easiest way to understand XML is through an example, so here is an XML document that represents a customer purchase order:

<?xml version="1.0"?>


  <customer_name>Alpha Technologies</customer_name>














The first line defines that the text that follows is an XML document that adheres to Version 1.0 of the XML specification. The second line is the root node of the document and has the tag <purchase_order>. A valid XML document must contain exactly one root node. Other nodes of the document can appear more than once as necessary to describe the data, as illustrated by the multiple <item> tags under the <po_items> tag. This document describes that Alpha Technologies issued P.O. #11257 on January 20, 2004, in which 20 units of part number AI5-4557 and 12 units of EI-T5-001 were requested. Since this document will be the basis for every example in this chapter, it would be worthwhile to become comfortable with it before forging ahead.

16.1.1 XML Resources

Because this book is about SQL, the focus of this chapter is how to utilize SQL to interact with XML documents. Thus, the XML examples used in this chapter are rather simple so as not to needlessly complicate things. If you are interested in delving deeper into XML, here are a few excellent resources:


The World Wide Web Consortium (W3C) site, useful for history of the XML specification, as well as the specification itself


Portal for everything XML, including tutorials, FAQs, white papers, news, etc.

XML in a Nutshell (O'Reilly)

An excellent reference guide for XML and related technologies

16.1.2 Oracle and XML

Oracle first began adding support for XML in the Oracle8i Database release. This support, which consisted largely of XML parser toolkits for Java, PL/SQL, and C/C++, allowed users to manipulate XML data but did not offer any native support for XML within the database kernel. The Oracle 9i Database releases raised the bar significantly by adding a new data type called XMLType for storing XML documents in the database and by creating a mechanism for organizing, accessing, and versioning XML documents called XML Repository. Oracle branded this set of technologies as Oracle XML DB. Additionally, XML data can be loaded and unloaded from a database using Oracle's import/export utilities, read from external files using SQL*Loader, and published via Advanced Queuing, making it clear that Oracle has made the integration of XML technologies a high priority over the past few releases.