Oracle8i Application Developer's Guide - XML
Release 3 (8.1.7)

Part Number A86030-01


Solution Area



Go to previous page Go to beginning of chapter Go to next page

Introduction to Oracle XML, 11 of 27

XML in the Database: Generated and Authored XML

Oracle8i supports different aspects to using XML in the database.

Generated XML

XML can be generated from object-relational tables and views. The benefits of using object-relational tables and views as opposed to pure relational structures are discussed below. Oracle provides a free utility, XML-SQL Utility (XSU) available for download from the Oracle Technology Network (OTN.

XML-SQL Utility (XSU) Converts SQL Query Results into XML

This utility converts the result of a SQL query into XML by mapping the query alias or column names into the element tag names and preserving the nesting of object types. The result representation can be in text or a DOM (Document Object Model) tree, the generation of the latter avoids the overhead of parsing the text to directly realize the DOM tree.

Mapping Between XML and the Database

There is a clean relationship between structured XML instances and object-relational types:

Database Mapping Example 1 (Java): Generating an XML Instance Corresponding to an SQL Query

For instance, the following Java code generates an XML instance corresponding to an SQL query.

public void testXML()
      new oracle.jdbc.driver.OracleDriver());

   //initialize a JDBC connection
   Connection conn = 

   //initialize the OracleXMLQuery; 
   OracleXMLQuery qry = 
	         new OracleXMLQuery(conn,
                   "select * from purchaseOrderTab");
   // set the document name
   // set the row element name
    // get the XML result
   String xmlString = qry.getXMLString(); 
    // print result
   System.out.println(" OUPUT IS:\n"+xmlString);

XML Example 2: XML Document Produced from Generic Mapping

The query in Example 4 selects all top level elements from the purchase order table and we use the generic mapping to get the following XML document:

<?xml version='1.0'?>
   <PurchaseOrder num="1">
           <street>200 Redwood Shrs</street>
           <city>Redwood City</city>
      <!-- more purchase orders. -->

The XML document created is an exact structural replica of the object type. Using object views, you can create such object-relational mappings from existing relational tables.

Go to previous page Go to beginning of chapter Go to next page
Copyright © 1996-2000, Oracle Corporation.

All Rights Reserved.


Solution Area