Team Fly 

Page 276

CRITICAL SKILL 8.3
SQLX: Create XML from Data Stored in Oracle

For years, organizations have been pouring their data into relational databases. If you're trading data with another organization, however, it's likely that you'll need to pull data out of your relational database and format that data as XML before transmitting it.

Let's first point out that generating XML from a relational source is a not a trivial task. It involves understanding how to map relational data into a hierarchal structure. On the other hand, creating the XML once you understand the mapping you want has been made easy.

The SQL/XML Standard

Oracle Database 10g implements a number of standards-based functions enabling you to query relational data and return XML documents. These functions collectively fall under the heading of SQL/XML, sometimes referred to as SQLX. SQL/XML is part of the ANSI/ISO SQL standard.

The international standard for SQL/XML defines the following elements:

Image XML A data type to hold XML data

Image XMLAgg A function to group, or aggregate, XML data in group by queries

Image XMLAttributes A function used to place attributes in XML elements returned by SQL queries

Image XMLConcat A function to concatenate two or more XML values

Image XMLElement A function to transform a relational value into an XML element, in the form: <elementName>value</elementName>

Image XMLForest A function to generate a list, called a ''forest," of XML elements from a list of relational values

Image XMLNamespaces A function to declare namespaces in an XML element

Image XMLSerialize A function to serialize an XML value as a character string

Oracle Database 10g has implemented the following XML data type (as XMLType), XMLAgg, XMLConcat, XMLElement, and XMLForest. Support for the other functions is planned in future releases. In addition to the functions and the data type, the SQL/XML standard defines rules for transforming column names into XML element names and for transforming SQL data types into XML data types. These rules are applied automatically by XMLElement and the other SQL/XML functions. Let's look at four of many SQLX functions that are commonly used to produce XML from the relational database.

Team Fly 
0295-CRITICAL SKILL 8.3 SQLX: Create XML from Data Stored in Oracle