Skip Headers

Oracle9i XML Database Developer's Guide - Oracle XML DB
Release 2 (9.2)

Part Number A96620-02
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Feedback

Go to previous page Go to next page
View PDF

26
Oracle XML DB Basic Demo

This chapter describes how to install and use the Oracle XML DB Basic Demo. It contains the following sections:

Prerequisites for Running the XML DB Basic Demo

You can also view and run this XML DB demonstration (demo) from: http://otn.oracle.com/tech/xml/content.html

Before you run the XML DB Basio demo ensure you have installed the following software:

Non-Oracle Software

Before installing and running the XML DB Basic demo, it is recommended that you install the following non-Oracle software:

Oracle Software

Before installing and running the XML DB demo, it is recommended that you install the following Oracle software:

Database SQL*NET and XML DB Configuration

Before starting the installation verify that Oracle Net Services, FTP, and HTTP are correctly configured using the following steps:

  1. Open a Windows Command Prompt session, change directory to the basicDemo directory, and use SQL*PLUS to connect to the target database as "SYS".


    Note:

    You will need to supply an appropriate TNSAlias in place of ORCL92.


    c:\...\BasicDemo>sqlplus "sys@ORCL92 as sysdba"
    
    
  2. Verify that the SCOTT schema has been created and that EMP and DEPT tables exist. If the SCOTT schema is not currently loaded it can be created using:
    SQL> @?\rdbms\admin\utlsampl.sql
    
    
  3. Confirm that Oracle XML DB is installed using:
    SQL> set long 100000 
    
    SQL> set pagesize 0
    SQL> select XDBUritype('/xdbconfig.xml').getXML() 
       2  from dual
       3  /
           
    

    If XML DB is correctly installed XML DB configuration documents will be displayed.

  4. Install the XDB_UTILITY package by running the following script:
    C:\...\basicDemo>sqlplus "sys@ORCL92 as sysdba"
    
    SQL*Plus: Release 9.2.0.1.0 - Production on Fri Aug 16 12:09:42 2002
    
    Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    
    Enter password:
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production With the 
    Partitioning, OLAP and Oracle Data Mining options 
    JServer Release 9.2.0.1.0 - Production
    
    SQL> @SQL/xdbUtility
    
    View created.
    
    PL/SQL procedure successfully completed.
    
    Package created.
    No errors.
    
    Package body created.
    No errors.
    
    Synonym created.
    Grant succeeded.
    
    SQL>
    
    
  5. Grant your target user execute privileges on the XDB_PORTS package:
    SQL> grant execute on XDB_UTILITY to SCOTT
        2  /
    
    
  6. Verify the current FTP and HTTP port settings on your system by selecting from the XDB_DATABASE_SUMMARY view:
    SQL> set long 10000
    SQL> select value(x) from XDB_DATABASE_SUMMARY (x)
      2  /
    
    

    This should generate the following output:

    VALUE(X)
     -----------------------------------------------------------------
    <Database Name="ORCL92" HTTP="8080" FTP="2100">
       <Services>
         <ServiceName>ORCL92.xp.mark.drake.oracle.com</ServiceName>
       </Services>
       <Hosts>
         <HostName>MDRAKE-LAP</HostName>
       </Hosts>
    </Database>
    
    

    Note:

    The preceding example shows the default XML DB port numbers set when XML DB is installed. These may not match the values in your environment.


  7. If the port numbers shown are not the required ports, you can use the following procedure to reconfigure the ports:
    • FTP:
      SQL> call XDB_UTILITY.SET_FTP_PORT(nnnn);
      
      
    • HTTP:
      SQL> call XDB_UTILITY.SET_HTTP_PORT(nnnn);
      
      

    In these preceding examples nnnn represents the target port number. The chosen FTP and HTTP port numbers cannot:

    • Be the same value
    • Be in by any other service on the system

    In general the selected port numbers should not be privileged port numbers (0-1023). After resetting the port numbers validate the new numbers have been accepted by repeating step 4.

  8. Verify that there are no HTTP or FTP port conflicts with other database instances running on the same host. You can do this by checking the status of the database Listener using the following command:
    C:\TEMP>lsnrctl status 
    
    

    If you are running against a remote database you should check the status from a DOS Command Prompt session or Telnet session attached to the remote machine.

  9. Examine the output of the status command. Verify that the Listener is monitoring HTTP and FTP requests on the port numbers identified in step 4. The Status command should generate output similar to the following:
    LSNRCTL for 32-bit Windows: Version 9.2.0.1.0 - Production on 05-AUG-2002 
    16:01:37
    Copyright (c) 1991, 2002, Oracle Corporation.  All rights reserved.
    Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC0)))
    STATUS of the LISTENER
    ------------------------
    Alias                     LISTENER
    Version                   TNSLSNR for 32-bit Windows: Version 9.2.0.1.0 - 
    Production
    Start Date                03-AUG-2002 21:45:08
    Uptime                    1 days 18 hr. 16 min. 28 sec
    Trace Level               off
    Security                  OFF
    SNMP                      OFF
    Listener Parameter File   C:\oracle\ora92\network\admin\listener.ora
    Listener Log File         C:\oracle\ora92\network\log\listener.log
    Listening Endpoints Summary...
            
    (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC0ipc)))
            (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=mdrake-lap)(PORT=1521)))
            (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=mdrake-lap)(PORT=8080))
                         (Presentation=HTTP)(Session=RAW))
            (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=mdrake-lap)(PORT=2100))
                         (Presentation=FTP)(Session=RAW))
    Services Summary...
    Service "ORCL92.xp.mark.drake.oracle.com" has 2 instance(s).
    Instance "ORCL92", status UNKNOWN, has 1 handler(s) for this service...
    Instance "ORCL92", status READY, has 2 handler(s) for this service...
    Service "ORCL92XDB.xp.mark.drake.oracle.com" has 1 instance(s).
    Instance "ORCL92", status READY, has 1 handler(s) for this service...
    Service "PLSExtProc" has 1 instance(s).
    Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
    The command completed successfully
    
    

    If the output from the Status command shows multiple entries for the HTTP and FTP presentations, check that no port number appears more than once. If a given port number appears more than once, it means that two or more database instances are trying to service that port. This is not permitted. All of the database instances running on a given host must be assigned unique FTP and HTTP port numbers.

  10. If multiple database instances have been configured to service the same port, ensure that unique port numbers are assigned for each instance.

    Connect to each instance in turn, and repeat steps 4, 5, 6, and 7, providing appropriate values for the FTP and HTTP ports. You can stop a database from servicing FTP and HTTP requests by setting the port number to 0. Once all of the database instances have been reconfigured, use the Listener Status command to check that each database instance has been reconfigured to service unique FTP and HTTP port numbers.

Verify SQL*NET and XML DB Configuration

Verify that Oracle Net Services (NET*8), FTP, and HTTP protocols are configured as expected using the following procedure. This example assumes that the TNSALIAS ORCL92 can be used to establish a connection to the target database.

  1. Verify the FTP configuration by connecting to the target database using FTP with the following commands:
    C:\temp >ftp -n
    ftp> open localhost 2100
    Connected to mdrake-lap.
    220 mdrake-lap FTP Server (Oracle XML DB/Oracle9i Enterprise Edition Release 
    9.2.0.1.0 - Production) ready.
    ftp> user scott tiger
    331 pass required for SCOTT
    230 SCOTT logged in
    
    

    When connecting to the FTP Server ensure that you replace:

    • localhost with the name of the server hosting the database instance
    • 2100 with the value of the target FTP port.
  2. Retrieve the contents of databaseSummary.xml file using the following commands:
    ftp> get /sys/databaseSummary.xml
    
    200 PORT Command successful
    150 ASCII Data Connection
    <Database Name="ORCL92" HTTP="8080"
    FTP="2100"><Services><ServiceName>ORCL92.xp.mark.drake.oracle.com</ServiceNa
    me></Services><Hosts><HostName>MDRAKE-LAP</HostName></Hosts></Database>226
    ASCII Transfer Complete
    ftp: 183 bytes received in 0.01Seconds 18.30Kbytes/sec.
    ftp>
    
    
  3. Verify the HTTP configuration by launching Internet Explorer and entering the URL contained in the HTTP tag into the address bar. For example:
    http://MDRAKE-LAP:8080/sys/databaseSummary.xml
    
    

    The Browser will prompt for a username and password. Enter the name and password of the database user that will be used when running the XML DB Basic Demo. If the HTTP configuration is correct the Browser should display the contents of the file:

    - <Database Name="ORCL92" HTTP="8080" FTP="2100">
    - <Services>
         <ServiceName>ORCL92.xp.mark.drake.oracle.com</ServiceName> 
      </Services>
    - <Hosts>
         <HostName>MDRAKE-LAP</HostName> 
      </Hosts>
      </Database>
    

Installing XML DB Basic Demo

To install XML DB Basic Demo unzip the file XDBBasicDemo.zip into a folder of your choice. When you unzip the installation file it creates folder basicDemo/. This folder contains a sub-folder install/. which in turn contains file install.vbs. install.vbs installs the XML DB Basic Demo.

Open a DOS Command Prompt session in the basicDemo/ directory. The following information is required in order to install this XML DB demonstration:

Editing installParameters.xml

install/ folder also contains file installParameters.xml that drives the installation process. This file contains arguments used to tailor the installation.

  1. Edit tinstallParameters.xml using a text or XML editor. The file is simple enough that it can easily be edited in Notepad. The file has the following format:
    <demoConfig>
          <oracleHome>c:\oracle\ora92</oracleHome> 
          <oracleUser>SCOTT</oracleUser> 
          <oraclePassword>TIGER</oraclePassword> 
          <oracleSID>ORCL92</oracleSID> 
          <sqlPort>1521</sqlPort> 
          <listenerName>LISTENER</listenerName> 
          <hostName>localhost</hostName> 
          <httpPort>8080</httpPort> 
          <ftpPort>2100</ftpPort> 
          <msWordPath>
                c:\Program Files\Microsoft Office\Office\WINWORD.EXE
         </msWordPath> 
          <ftpPath>c:\Program Files\WS_FTP\WS_FTP95.exe</ftpPath> 
          <shortCutFolderName>XML DB Basic Demo</shortCutFolderName> 
    </demoConfig>
     
    
  2. Make any changes required. Pay special attention to the values for:
    • <oracleHome>
    • <oracleSID>
    • <httpPort>
    • <ftpPort>
  3. Save the file. After editing installationParameters.xml file verify that the file still contains well-formed XML by opening it in Internet Explorer.

Running the Installation Script

Carry out these steps to run the XML DB demo installation script:

  1. Run the installation script by double-clicking the install.vbs script. See Figure 26-1. The script prompts you for confirmation before starting the configuration process:

    Figure 26-1 Prompting You for Confirmation

    Text description of image001.jpg follows.

    Text description of the illustration image001.jpg

  2. Click OK to configure the demo.

    At the end of the installation process the script will report installation complete.

    Figure 26-2 Installation Complete

    Text description of image002.jpg follows.

    Text description of the illustration image002.jpg

  3. Click OK to complete installation of the demonstration.


    Note:

    If it turns out that the values supplied using installParameters.xml were not correct, they can be correct by editing the file and then re-executing the install.vbs script.


What is Oracle XML DB?

Oracle XML DB is the term for set of features in Oracle9i Release 2 (9.2) database that deliver high-performance storage and retrieval of XML. These features allow the database to absorb the W3C XML data model. The technology included with Oracle9i Release 2 means that the database is now a native XML database in addition to being the most complete relational database.

New Methods for Navigating and Querying XML

Oracle XML DB provides organization with a storage independent, content independent, and programming language independent infrastructure to store and manage XML data. It also provides new methods for navigating and querying XML content stored inside the database. With Oracle XML DB, you get all the advantages of relational database technology and XML technology at the same time.

Several Options for Storing XML in the Database

Oracle XML DB offers a number of options for managing how XML documents will be stored in the database. Options include:

Fully Supports XPath Access Methods

As anyone who has worked with XML quickly realizes, XML is closely tied to hierarchical metaphors. The standard mechanism used to query or access content contained in an XML Document is XPath. XPath is a W3C standard that defines a language for addressing parts of an XML document. XPath uses a path-based notation to navigate through the hierarchical structure of an XML document. When an XML document needs to refer to another XML document, the standard way to reference the target document is using a URL. Like XPath, URLs uses a path-based notation to identify the document in question. Oracle XML DB provides full support for these access methods.

Use XPath Expressions to Query and Update XML

A number of the features provided by Oracle XML DB allow you to use XPath expressions to query and update content in XML Documents. Oracle XML DB also includes a simple, light-weight, Repository that allows the relationships between XML documents to be expressed using a URL. This Repository also makes it possible to access XML content using a URL. This means that you have the option of accessing XML objects using both relational and hierarchical mechanisms.

Oracle XML DB Components

The major components of Oracle XML DB are:

Starting the XML DB Basic Demo

To start the XML DBBasic Demo, open the folder XML DB Basic Demo. If the demo has been installed correctly this folder will be located on your Desktop. Figure 26-3 displays the icons you will see when you open the BasicDemo/ folder.

Figure 26-3 XML DB basic Demo Folder Icons

Text description of image003.jpg follows.

Text description of the illustration image003.jpg

As you can see, the icons in this folder are numbered. The demonstration is given by clicking on each of the icons in this folder in turn.

0.1 XML DB Demo: Initial Setup (Run Once)

Before giving the demonstration for the first time you must run this script.

This script does not need to be run again unless the database is dropped and re-created. The script does the following:

Some of these operations may generate errors if the demo is run as user SCOTT. You can ignore these.

0.2 XML DB Demo: Resetting the Demo

Prior to giving the demonstration it is necessary to run this script. This script will remove all files under the chosen user's home folder and ensure that the environment is clean. Operations like deleteSchema() may generate errors. These can be safely ignored.

1.0 XML DB Demo: XML DB on localhost - WebDAV and FTP Support

This step demonstrates the native WebDAV support included as part of Oracle XML DB. Click the 1.0 localhost icon to open a Web Folders (WebDAV) session to XML DB Repository. You will be prompted for username and password. Enter the appropriate database user and password and click OK. Figure 26-4 shows the displayed window.

Figure 26-4 XML DB on Localhost

Text description of image004.jpg follows.

Text description of the illustration image004.jpg

Key Points:

Figure 26-5 Creating a New Folder

Text description of image005.jpg follows.

Text description of the illustration image005.jpg

Give the new folder a clearly identifiable name.

Key Points:

Do not close the window at this point.

1.1 Using SQL to Make Directories

This step demonstrates that Oracle XML DB Repository can be accessed and updated from SQL, as well as through protocols. It also shows that, when accessed using SQL, Repository operations are transactional.

  1. Execute the SQL script by clicking on the icon 1.1 Make Directories.

    Figure 26-6 Making Directories

    Text description of image006.jpg follows.

    Text description of the illustration image006.jpg

    The script create a set of folders inside folder /home/SCOTT.

  2. Do not close the SQL*PLUS session at this point.

    Key Points:

    • Oracle XML DB Repository SQL as well as standard protocols such as WebDAV and FTP will be used to access and manipulate the Repository.
    • PL/SQL package DBMS_XDB can be used to perform operations on the Repository from SQL. This means that any program that can call a PL/SQL procedure can work with Oracle XML DB Repository.
  3. Click the window containing the WebDAV view of /home/SCOTT. Click the Refresh option. Note that the folders that were created by executing the PL/SQL script are NOT visible, even after refreshing the display.

    Key points:

    • This is the expected behavior. PL/SQL operations are transactional, and the transaction has not been committed. Consequently the changes made in the PL/SQL session are not visible to other users.
  4. Click the Window containing the SQL*PLUS session and commit the transaction. Close the SQL*PLUS window.
  5. Click the window containing the WebDAV view of /home/SCOTT. Click the Refresh option. Note that the folders created by executing the PL/SQL script are now visible.

    Figure 26-7 Executing the PL/SQL Script: Folders are Visible

    Text description of image007.jpg follows.

    Text description of the illustration image007.jpg

  6. Close the SQL*PLUS window by typing QUIT at the SQL> prompt. Close the WebDav window.

1.2 Using FTP to Load Configuration Files

This shows how a standard FTP client can load documents into Oracle XML DB Repository. This step assumes that you are using WS_FTP95 from Ipswitch software. The reason this client was used is that it can be configured to make it easy to run the demonstration. In practice any FTP client can be used. If you choose to use WS_FTP ensure that you have a legal license.

  1. Click the 1.2 Load Configuration Files icon to open the FTP Client and establish an FTP connection to XML DB Repository.

    Figure 26-8 Loading Configuration Files

    Text description of image008.jpg follows.

    Text description of the illustration image008.jpg

  2. Enter the database user's password and click OK. The FTP Client will connect to the database. The dialog in Figure 26-8 is displayed:
  3. Enter the password for your user and click OK. After entering the password the window in Figure 26-9 is displayed.

    Figure 26-9 Displaying the FTP Client

    Text description of image009.jpg follows.

    Text description of the illustration image009.jpg

  4. Click the SCOTT folder in Local System pane, and then click the lower arrow to transfer the SCOTT folder from the local hard drive to Oracle XML DB Repository. If prompted to confirm the operation do so. When the operation has completed click Exit.

    If you choose to use a different FTP tool then you need to ensure that all the files and folders under local SCOTT folder are copied to the /home/SCOTT folder in Oracle XML DB Repository. The local version of the SCOTT folder is located in basicDemo\LOCAL\Configuration Files.

    Key Points:

    • A standard FTP Client, which has no knowledge of Oracle or the Oracle XML DB has been used to upload a set of documents into Oracle XML DB Repository.
    • This procedure uploaded a directory tree containing an XML schema document, an HTML page, and a couple of XSLT style sheets.
    • The Oracle XML DB repository can be used to store non XML content, such as HTML files, JPEG images, word documents etc, as well as Schema based and non-Schema based XML content.
  5. Close the FTP Client by clicking on the Exit button.

2.0 XML DB Demo: XML Schema - How XML DB Shreds and Stores XML

This step introduces the concept of XML Schema and Oracle XML DB's ability to shred and store XML documents using structured storage based on SQL99 object types. It uses XMLSpy from Altova.

Key Points:

In this demo, one of the documents loaded into the database was an XML schema. This step uses XMLSpy to demonstrate the key features of Oracle XML DB's support for the W3C XML Schema Recommendation.

  1. Click the icon to launch XMLSpy. Click the + sign next to the DTD/Schemas entry in the Project Window. This branch should contain an item called http://mdrake-lap:8080/home/SCOTT/xsd/purchaseOrder.xsd. Double click this item to open it.
  2. You will be prompted for the database password.

    Enter the password and Click OK.

    XMLSpy displays a graphical representation of the elements and types defined by the PurchaseOrder XML schema.

    Figure 26-10 XMLSpy's Graphical Representation of Elements and Types Defined by the XML Schema

    Text description of image010.jpg follows.

    Text description of the illustration image010.jpg

  3. Click the control button next to the PurchaseOrder element. Then click the + sign next to the lineItems element, followed by the + sign next to the lineItem element. Finally click the part element.

    At this point XMLSpy displays a graphical representation of the PurchaseOrder XML schema.

    Figure 26-11 XMLSpy Displays the PurchaseOrder XML Schema

    Text description of image012.jpg follows.

    Text description of the illustration image012.jpg

    Key Points:

    • XMLSpy supports both WebDAV and FTP protocols. This allows XMLSpy to directly access content stored in Oracle XML DB.
    • The global element PurchaseOrder is an instance of the complexType PurchseOrderType. PurchaseOrderType defines a set of elements that make up a PurchaseOrder document. One of these is LineItems which contains a collection of LineItem elements.
    • Each LineItem elements consists of two elements, Description and Part.
    • Part element has attributes Id, Quantity, and UnitPrice.
    • The PurchaseOrder schema is a relatively simple XML schema that demonstrates the key features of a typical XML document. What is being viewed here is a graphical representation of the XML schema.
  4. Click the control button on the Toolbar to switch to the textual view of the XML schema. This displays the XML schema, in its native form. It is an XML document that conforms to the Schema for Schema defined by the W3C XML Schema committee.

    Figure 26-12 XML Schema Displayed in Native Form, an XML Document

    Text description of image014.jpg follows.

    Text description of the illustration image014.jpg

    Key Points:

    • This XML schema defines two namespaces:
      • http://www.w3c.org/2001/XMLSchema, is the namespace reserved by the W3C consortium for the Schema for Schemas. This namespace is used to define the structure of the XML document.
      • http://xmlns.oracle.com/xdb is the namespace reserved by Oracle for Oracle XML DB annotations schema annotations. This namespace is used to add annotations to the schema that control how the instance documents will be stored in the database.

      The annotation mechanism is the W3C approved mechanism for adding Vendor-specific information to a W3C XML Schema.

    • Oracle XML DB can register a schema which contains no annotations. It makes use a set of default assumptions to register the Schema. The annotations provide the application developer or database administrator with the ability to override these assumptions.
    • Annotations can be used to override the following:
      • The naming of Tables, SQL Objects and SQL Attributes.
      • How collections are managed
      • The mapping between XMLSchema data types and SQL data types.
    • In this schema the following annotations are being used:
      • The defaultTable annotation is used in the PurchaseOrder element to define that XML documents, compliant with this schema will be stored in a table called PURCHASEORDER.
      • The SQLType annotation is used to provide an explicit name for the SQL Type that will be generated form the complexType PurchaseOrderType.
  5. Click the control button on the Toolbar to switch back to the graphical view of the XML schema.

    Figure 26-13 A Graphical View of XML Schema

    Text description of image016.jpg follows.

    Text description of the illustration image016.jpg

    Key Points:

    • XMLSpy provides an Oracle tab that allows Oracle XML DB schema annotations to be entered while working in graphical editing mode.
  6. Click the icon next to the PurchaseOrderType complexType.
  7. Do not close this window yet.

2.1 Registering XML Schema

This step demonstrates how to make Oracle XML DB aware of an XML schema. At this point in the demonstration the XML schema has simply been stored in the Oracle XML DB Repository. The database is not aware of the existence of the XML schema.

See Also:

Chapter 5, "Structured Mapping of XMLType"

  1. Execute the SQL script by clicking on the 2.1 Register XML Schema icon.

    Figure 26-14 Executing the dbms_xmlschema.registerSchema Script

    Text description of image017.jpg follows.

    Text description of the illustration image017.jpg

    Key Points:

    • The XML schema is registered under a URL. The URL is the URL that an XML instance document will use to identify itself as a member of the class defined by the XML schema.
    • The method for identifying an XML document as a member of the class of documents defined by the XML schema is defined by the W3C XML Schema Working Group.
    • The URL is simply a key used to associate the instance document with the registered XML schema. Oracle XML DB does need to be able to access the URL.
    • The registerSchema() procedure is responsible for creating all of the objects and type defined by the XML schema.
  2. Close the SQL*PLUS window by typing QUIT at the SQL> prompt.

2.2 Objects Are Created With XML Schema Registration

This step shows some of the objects created as a result of registering the XML schema.

  1. Execute the SQL script by clicking on the 2.1 Show Objects Icon.

Figure 26-15 Using DESCRIBE to List Objects Created During XML Schema Registration

Text description of image018.jpg follows.

Text description of the illustration image018.jpg

Key Points:

3.0 XML DB Demo: How XML Files Conform to the XML Schema

This step demonstrates that the sampleData folders on your local hard-drive contain instance documents that conform with the registered XML schema.

  1. Click the 3.0 Sample Files icon to open the sampleData folder. Open folder 1999. Open the folder Apr. Right click the document ADAMS-20011127121040988PST.xml and select Open.

    This should launch Internet Explorer and display the document. If the document opens with some other application use the FolderOptions feature of Windows Explorer to adjust the file association.

    Figure 26-16 Displaying Document ADAMS-2011127121040988PST.xml

    Text description of image019.jpg follows.

    Text description of the illustration image019.jpg

    Key Points:

    • The file is compliant with the XML schema.
    • The noNamespaceSchemaLocation attribute is used to identify the document as an instance of the class of documents defined by the XML schema.
  2. Close Internet Explorer and the sampleData/1999/Apr window. Re-Open the Demonstration Folder, located on your Windows Desktop.

3.1 Using FTP to Load Instance Documents

This step involves using FTP to copy the 1999 folder tree into Oracle XML DB Repository. It demonstrates how Oracle XML DB recognizes the documents as instances of the registered XML schema, and processes them accordingly.

  1. Click this icon to open the FTP Client and establish an FTP connection to XML DB Repository. Enter the database user's password when prompted and click OK. After entering the password the following window is displayed.

    Figure 26-17 Using FTP to Copy 1999 Structure to Oracle XML DB Repository

    Text description of image020.jpg follows.

    Text description of the illustration image020.jpg

  2. Click the 1999 folder in the Local System pane, and then click the lower arrow to copy the 1999 folder, and all of it's subfolders from the local hard drive to the home/SCOTT/purchaseOrders folder in Oracle XML DB Repository. When the operation has completed click Exit.

    Key Points:

    • A standard FTP client has been used to load content directly into the Oracle database. No additional moving parts or servers were required. This is possible because Oracle XML DB supports FTP and HTTP/WebDAV, a set of protocols understood by the database.
    • Since the root node of each document included a noNameSpaceSchemaLocation attribute that identified them as a instance of the registered XML schema, the documents were shredded and stored as a set of objects in the database.
  3. Close the FTP client by clicking the EXIT button.

3.2 Using SQL to Add Constraints to XML Data

This step involves showing how you can leverage SQL functionality when storing XML documents in Oracle XML DB. Adding constraints to the table constrains the XML data. This step also enables full XML schema validation of the XML documents.

See Also:

Chapter 4, "Using XMLType"

Key Points:

  1. Execute the SQL script by clicking on the 3.2 Add Constraints icon.

    Figure 26-18 Adding Constraints and Creating Triggers

    Text description of image021.jpg follows.

    Text description of the illustration image021.jpg

    Key Points:

    • Currently SQL'99 Object syntax has to be used when defining constraints. A future release of Oracle XML DB will allow constraints to be defined using more intuitive XPath expressions.
    • The contents of a row in an XMLType table has to referred to as SYS_NC_ROWINFO$ from within a Trigger.
    • Schema-validation is performed by invoking the schemaValidate() method on the XMLType. Using a Trigger makes it possible to for the validation to return meaningful error messages, and for you to catch these errors and attempt corrective action where appropriate.
    • The first constraint ensures that the value of the element identified by the XPath expression /PurchaseOrder/Reference is unique across all PurchaseOrder documents stored in the PURCHASEORDER table.
    • The second constraint ensures that the value of the element identified by the XPath expression /PurchaseOrder/User can be found in the ENAME column of the table SCOTT.EMP.
    • The Trigger ensures that full XML schema-validation takes place on every document loaded in table PURCHASEORDER.
  2. Close the SQL*PLUS window by typing QUIT at the SQL> prompt.

3.3 Using FTP to Upload XML Documents that Attempt to Violate the Constraints

This step involves using FTP to (attempt to) upload a set of documents that violate constraints created in the previous step.

  1. Click the 3.3 Violate Constraints icon to open the FTP Client and establish an FTP connection to XML DB Repository.
  2. Enter the database user's password when prompted and click OK. After entering the password the following window is displayed.

    Figure 26-19 Opening the FTP Client to Establish an FTP Connection

    Text description of image022.jpg follows.

    Text description of the illustration image022.jpg

  3. Click the Duplicate ADA~ file in Local System pane, and then click the lower arrow to copy the document copy to the purchaseOrders folder in Oracle XML DB Repository:

    Figure 26-20 FTP Error Caused From Violating the UNIQUE Constraint

    Text description of image023.jpg follows.

    Text description of the illustration image023.jpg

    When the document is uploaded the following error is displayed:

    ORA-00604: error occurred at recursive SQL level 1
    ORA-00001: unique constraint (SCOTT.REFERENCE_IS_UNIQUE) violated
    
    

    Uploading this document resulted in a violation of the REFERENCE_IS_UNIQUE constraint created in step 3.2. This is because the value of the node PurchaseOrder/Reference/text() in this document is identical to the value of the node in one of the documents that was loaded during step 3.1. Consequently the operation fails.

  4. Next, click the HACKER-200111~ file in Local System pane, and then click the View button.


    Note:

    The value of the node /PurchaseOrder/User/text() is "HACKER".


  5. Click the lower arrow to copy the document copy to the purchaseOrders folder in Oracle XML DB Repository.

    Figure 26-21 FTP Error Caused From Violating the USER_IS_VALID Constraint

    Text description of image024.jpg follows.

    Text description of the illustration image024.jpg

    When the document is uploaded the following error is displayed

    ORA-00604: error occurred at recursive SQL level 1
    ORA-02291: integrity constraint (SCOTT.USER_IS_VALID) violated - parent key 
    not found
    
    

    Uploading this document resulted in a violation of the USER_IS_VALID constraint created in step 3.2. This is because the value of the node PurchaseOrder/User/text() in this document is "HACKER", and this value was not found in the ENAME column in SCOTT.EMP. Consequently the operation fails.

  6. Next, click the Invalid Purch~ file in Local System pane, and then click the View button.


    Note:

    The value of the node /PurchaseOrder/Reference/text() is "ADAMS-20011127PST".


  7. Click the lower arrow to copy the document copy to the purchaseOrders folder in Oracle XML DB Repository.

    Figure 26-22 FTP Error Caused From Firing the VALIDATE_PURCHASEORDER Trigger

    Text description of image025.jpg follows.

    Text description of the illustration image025.jpg

    When the document is uploaded the following error is displayed

    ORA-00604: error occurred at recursive SQL level 1
    ORA-31154: invalid XML document
    ORA-19202: Error occurred in XML processing
    LSX-00221: "ADAMS-20011127PST" is too short (minimum length is 18)
    ORA-06512: at "SYS.XMLTYPE", line 0
    ORA-06512: at "SCOTT.VALIDATE_PURCHASEORDER", line 5
    ORA-04088: error during execution of trigger 'SCOTT.VALIDATE_PURCHASEORDER'
    
    

    Uploading this document resulted in the VALIDATE_PURCHASEORDER Trigger being fired. The XML schema=validation processing performed in the Trigger detected that the value of the node /PurchaseOrder/Reference/text() did not conform to the rules set out in the XML schema. The schema defines that the minimum length of this node should be 18 characters. Since the document is not a valid instance of the class of documents defined by the XML schema, the operation fails.

    Key Points:

    • Can use constraints and triggers to enforce integrity of XML documents. By using the database to manage XML you receive the power of SQL combined with the flexibility of XML.
    • Constraints and triggers are enforced even when protocols are used to upload content into the database.
    • By storing XML documents in Oracle XML DB, organizations can bring the Reliability, Availability, Scalability and Security of the Oracle database to bear on XML content.
  8. Close the FTP Client by clicking on the EXIT button.

4.0 XML DB Demo: Simple XPath Queries Against XML Documents

This step demonstrates ways to execute simple XPath queries against XML documents.

See Also:

Chapter 4, "Using XMLType"

  1. Execute the SQL script by clicking on the 4.0 Simple Queries icon.

    Figure 26-23 Using existsNode() in the WHERE Clause to Restrict Which Documents Are Returned

    Text description of image026.jpg follows.

    Text description of the illustration image026.jpg

    Key Points:

    • Simple Queries can be stated using familiar SQL syntax.
    • The existsNode() SQL/XML operator can be used in the WHERE clause to restrict the set of documents returned by a query. existsNode() applies an XPath expression to an XML document and returns true (1) or false (0) depending on whether or not the document contains a node that matches the XPath expression.
    • XPath is a W3C standard for querying and accessing the content of an XML document and is a familiar syntax to XML programmers and authors.
    • The first example shows how to find the number of PurchaseOrder documents by counting the number of rows in the PurchaseOrder table. There will be one row in the table for each document.
    • The second example shows how to use the existsNode() function and a simple XPath expression to find the number of PurchaseOrder documents where the value of the node PurchaseOrder/User/text() contains the value "SMITH".
    • The third example shows how to use the value() operator to display the entire contents of a document stored as a row in an XMLType (object) table. It also show how to use the existsNode() operator to restrict the result to the row where the node /PurchaseOrder/Reference/text() contains the value "ADAMS-20011127121040988PST".
    • Close the SQL*PLUS window by typing QUIT at the SQL> prompt.

4.1 More Complex XPath Queries on XML Documents

This example shows how to use the extractValue() clause to get the value of a node in a document based on an XPath expression. It also shows that Oracle XML DB is capable of evaluating complex XPath expressions that involve deep navigation of an XML document.

  1. Execute the SQL script by clicking on the 4.1 Simple Queries (2) icon.

    Figure 26-24 Using extractValue() to Get a Node Value Based on an XPath Expression

    Text description of image027.jpg follows.

    Text description of the illustration image027.jpg

    Key Points:

    • The existsNode() function is used to restrict the set of documents returned by the query to those that by that contain a lineItem element that contains a part element with an Id attribute containing the value "037429139523".

      The lineItem element occurs multiple times within each document.

    • Since the XPath /PurchaseOrder/LineItems/LineItem/Part[@Id="037429139523"] does not explicitly identify which occurrences to search, all instances of the lineItem element are searched to see if they meet the specified condition.
    • The extractValue() function is used to return just the value of the node identified by the XPath expression: /PurchaseOrder/Reference/text()
    • Oracle XML DB is able to efficiently evaluate complex XPath expressions.
  2. Close the SQL*PLUS window by typing QUIT at the SQL> prompt.

4.2 EXPLAIN Plan of Queries on XML Tables

This step looks at the EXPLAIN plans generated by executing queries against tables of XML documents.

  1. Execute the SQL script by clicking on the 4.2 Explain Plan (1) icon.

    Figure 26-25 EXPLAIN Plan of Query to Retrieve XPath Node Documents

    Text description of image029.jpg follows.

    Text description of the illustration image029.jpg

    Key Points:

    • This EXPLAIN plan shows the query for retrieving documents that contain a node identified by XPath: /PurchaseOrder[Reference="ALLEN-2001101709512118PDT.
    • The query is resolved using a UNIQUE index. The UNIQUE index was created when the UNIQUE constraint was added to the table.
    • Query Rewrite allows the XPath expression to be translated into an indexed access. Since the XML schema for the document is known, and the storage model derived from the XML schema is known, Oracle XML DB can re-write the XPath expression into an object-relational SQL query against the underlying object model.
    • The Oracle Optimizer can then optimize that query and evaluate the optimal plan for returning the result set.

    Figure 26-26 EXPLAIN Plan for Query Counting Number of Documents at Node

    Text description of image030.jpg follows.

    Text description of the illustration image030.jpg

    Key Points:

    • This EXPLAIN plan shows the query for counting the number of documents which contain a node identified by the XPath expression "/PurchaseOrder[User="SMITH"]".
    • The query is resolved using a table scan. This is fine with 168 documents that make up the sample data used in this demonstration, but not acceptable in a real world scenario where the table could contain millions of documents.
    • Close the SQL*PLUS window by typing QUIT at the SQL> prompt.

4.3 Using extractValue() and an XPath Expression to Create XML Indexes

This step looks at how to use an XPath expression to create an index. You can eliminate the table scan by building an index to support the second query in the previous example.

  1. Execute the SQL script by clicking on the 4.3 Create XML Indexes icon or similar.

    Figure 26-27 Creating an Index Using extractValue() and XPath Notation

    Text description of image031.jpg follows.

    Text description of the illustration image031.jpg

    Key Points:

    • To eliminate the table scan build an index for resolving the query.
    • The index is defined using the same XPath notation used to express the query.
    • The index is not a function-based index. Query Rewrite helps map the XPath expression supplied in the CREATE INDEX statement on the appropriate attribute(s) of the underlying object(s). A conventional B-Tree index is then created on these attributes.
  2. Close the SQL*PLUS window by typing QUIT at the SQL> prompt.

4.4 Using EXPLAIN Plan to Determine if the Index is Being Used

This step demonstrates that the newly created index is used to resolve the query.

  1. Execute the SQL script by clicking on the 4.4 Explain Plan (2) Icon.

    Figure 26-28 Running an EXPLAIN Plan to Determine if the New Index is Being Used

    Text description of image032.jpg follows.

    Text description of the illustration image032.jpg

    Key Points:

    • The new index is used automatically. The application did not need re-writing.
    • For the database administrator nothing changes. The same skills are still required. Create the indexes required to allow queries to execute efficiently. Monitor index usage. Drop indexes that are not contributing to query performance.
  2. Close the SQL*PLUS window by typing QUIT at the SQL> prompt.

5.0 XML DB Demo: Using HTTP to Access XML Content

Previous steps have shown how FTP can be used to load XML content in Oracle XML DB, and how the content can be accessed using the familiar SQL Table/Row metaphor. This step shows how HTTP protocol can be used to access content stored in Oracle XML DB using a Path-based (Folder/File) metaphor.

See Also:

Chapter 4, "Using XMLType"

  1. Click the 5.0 ADAMS-2001... icon to launch Internet Explorer and display the target document. When prompted, enter the database username and password.

    Figure 26-29 Using HTTP: Accessing XML Content

    Text description of image033.jpg follows.

    Text description of the illustration image033.jpg

    The PurchaseOrder document is displayed on the Browser. See Figure 26-30.

    Figure 26-30 PurchaseOrder XML Document is Displayed

    Text description of image034.jpg follows.

    Text description of the illustration image034.jpg

    Key Points:

    • Oracle XML DB allows access to content using both the SQL-centric, Table/Row metaphor the document-centric Folder/File metaphor.
    • Content can be accessed direct from a Web Browser using a simple URL.
    • Oracle XML DB provides native support for HTTP protocol. No Web Servers, plug-in technology, adaptors or controls are required to enable this functionality.
    • Protocol support can be turned off if required
    • Protocol support is based on the same architecture as SQL*NET shared server mode, namely the Oracle Listener and Shared Server Mode server.
  2. Do not close the Browser window at this point.

5.1 SQL Can Display the Retrieved XML Document Through XDBUriServlet

This step demonstrates that the File/Folder metaphor can be used to access content even when working in SQL.

  1. Execute the SQL script by clicking on the 5.1 Show Document(1) icon.

    Figure 26-31 Accessing Content by Specifying Files/Folders

    Text description of image035.jpg follows.

    Text description of the illustration image035.jpg

    Key Points:

    • Path-based access to content is also available from SQL. The XDBUriType makes it possible to use a path-based metaphor to access content stored in Oracle XML DB Repository.
    • XDBUriType provides a set of methods that make it possible to access different types of contents. Any path provided to XDBUriType is assumed to originate from the root of Oracle XML DB Repository.
  2. Do not close the SQL*PLUS window at this point

5.2 Editing XML Documents with WebDAV-Enabled Tools

This step illustrates Oracle XML DB's WebDAV support and how you can use standard WebDAV-enabled tools to access and update content stored in the Repository.

  1. Click the 5.2 Edit Document icon to launch Microsoft Word and open the target document. When prompted enter the required username and password. If prompted for file conversion or character set conversion select the default values recommended by Word. The document will display in Word.

Figure 26-32 Using WebDAV Tools Such as Microsoft Word to Edit an XML Document

Text description of image036.jpg follows.

Text description of the illustration image036.jpg

Use Microsoft Word to edit the document. Update the value of the node /PurchaseOrder/Actions[1]/Action/User/text() to "VISHU". Be very careful when typing the value VISHU, as later steps in the demonstration depend on your making this change correctly. Save the changed document.


Note:

You cannot use Notepad or WordPad currently. You must use a WebDAV aware editor such as Word/2000 or Word/XP.


Key Points:

5.3 Displaying and Verifying Updates Made to XML Documents, Using SQL

This step shows that the changes made using Microsoft Word are visible from SQL.

  1. If the window from step 5.1 is still open simply type a `/' character to re-execute the query. If the window from step 5.1 has been closed, click the 5.3 Show Document (2) icon to execute the query.

Figure 26-33 Changes Made Using Microsoft Word Are Also Visible Using SQL!

Text description of image037.jpg follows.

Text description of the illustration image037.jpg

Key Points:

  1. Close the SQL*PLUS window by typing QUIT at the SQL> prompt.

5.4 Updating XML Documents Using SQL

This step shows how an XML Document can be updated using SQL. It shows the use of the updateXML() function to update the contents of an XML document stored as XMLType. It refers to the target node using an XPath expression.

See Also:

Chapter 4, "Using XMLType"


Note:

For this step to work correctly Step 5.2 must have been successfully completed.


  1. Execute the SQL script by clicking on the 5.4 Update Document icon.

    Figure 26-34 Updating an XML Document Using updateXML() and an XPath Expression in the WHERE Clause

    Text description of image038.jpg follows.

    Text description of the illustration image038.jpg

    Key Points:

    • The updateXML() function can be used to update the contents of an XML document stored as an XMLType.
    • updateXML() uses an XPath expression to identify the element, attribute or node that is to be updated.
    • updateXML() works with both XML schema-based and non-schema based content.

      For XML schema-based content, Query Rewrite allows updateXML() to perform in-place updates. If the XPath expression can be mapped onto an attribute of one of the underlying SQL Objects the update is performed as an SQL operation.

    • updateXML() is a much more efficient way of updating XML schema-based documents.
      • When Microsoft Word updates a document, Oracle XML DB cannot tell which parts of the document were altered. Consequently it is forced to parse the entire document and update all of the database objects based on the new document.
      • When updateXML() updates a document, only the parts of the document that change are updated.
      • When updateXML() is used to update non-schema-based XML the update is done by instantiating a DOM and performing the update on the DOM. The DOM is then printed, and written back to the underlying CLOB storage.
    • Changes made with updateXML() are just like any other changes made using SQL. They must be committed before they become visible to other database users.
  2. Close the SQL*PLUS window by typing QUIT at the SQL> prompt.

5.5 Displaying Changes Made to an XML Document Using Both XML and SQL

This step shows the duality of the SQL and XML approaches.

  1. If the window from step 5.0 is still open use ctrl-refresh to reload the contents of the Browser. If the window from step 5.1 has been closed, click the 5.5 ADAMS-200111... icon to open the Browser and display the document.

    Figure 26-35 Interoperability of XML and SQL: Accessing XML Content Using SQL

    Text description of image039.jpg follows.

    Text description of the illustration image039.jpg

    Key Points:

    • Both the changes made using Microsoft Word and the change made using SQL are visible in the refreshed page.
    • Oracle XML DB provide full XML/SQL duality and interoperability. XML content can be accessed and updated using both a document-centric file/folder metaphor, and a SQL-centric table/row metaphor.
    • Changes made using one approach are available to the other approach as soon as the transaction is committed.
  2. Close the Browser Window.

6.0 XML DB Demo: Querying RESOURCE_VIEWS Using SQL

This step provides more detail about Oracle XML DB Repository and shows how SQL programmers can use RESOURCE_VIEW to query the Repository contents.

See Also:

Chapter 15, "RESOURCE_VIEW and PATH_VIEW"

Key Points:

  1. Execute the SQL script by clicking the 5.0 Resource_Views Query (1) icon.

    Figure 26-36 Querying RESOURCE_VIEW Using EQUALS_PATH()

    Text description of image040.jpg follows.

    Text description of the illustration image040.jpg

    Key Points:

    • The RESOURCE_VIEW provides the primary public view of Oracle XML DB Repository. It contains 1 row for each document or folder in the Repository. Each row contains 2 columns, RES and ANY_PATH:
      • RES is an XML document containing the meta data about a document stored in the Repository.
      • ANY_PATH contains a valid path, from the root of the Repository that the current user can use to access the document.
    • RESOURCE_VIEW and PATH_VIEW can be accessed just like any other views. For instance to count the document of documents in the Repository simply count the number of rows in the RESOURCE_VIEW.
      • ACL-based security ensures that the query "select count(*) from RESOURCE_VIEW" returns the number of documents that the user has access to.
    • Functions such as UNDER_PATH make it easy to efficiently restrict a query to a particular sub-tree of the Repository.

    Figure 26-37 Using EQUALS_PATH() to Retrieve Metadata About the purchaseOrder Folder Through RESOURCE_VIEW

    Text description of image041.jpg follows.

    Text description of the illustration image041.jpg

    Key Points:

    • The RES column contains an XML document that conforms with the XDBResource XML schema. This schema defines the set of metadata required to implement the IETF WebDAV standard.
    • The example uses the EQUALS_PATH() function to retrieve the metadata for the user's purchaseOrder folder.
    • The available metadata includes items like DisplayName, Creator, Owner, LastModifier, CreationDate, and ModificationDate.
    • The resource can be accessed just like any other XML document stored in Oracle XML DB. extractValue() and existsNode() can be used for performing queries against the RESOURCE_VIEW.

    Figure 26-38 Using extractValue() and UNDER_PATH() to Walk the Directory Tree Starting at the purchaseOrder Folder

    Text description of image042.jpg follows.

    Text description of the illustration image042.jpg

    Key Points:

    • extractValue() can be used to access the metadata. Operations that involve updating the metadata, such as changing the owner of a document can be performed using updateXML().
    • Queries against the set of resources managed by a repository can be performed using functions like existsNode(), UNDER_PATH() and EQUALS_PATH().

    This example uses extractValue() and UNDER_PATH() to walk the directory tree starting from the user's purchaseOrders/ folder.

  2. Close the SQL*PLUS window by typing QUIT at the SQL> prompt.

6.1 XPath-Based Querying of RESOURCE_VIEWS Using Hierarchical Indexing

This demonstrates how you can query against XML DB Repository and use the Hierarchical Index feature to efficiently resolve path-based queries.

  1. Execute the SQL script by clicking the 6.1 Resource View Queries (2) icon.

Figure 26-39 Using Standard SQL Syntax to Search the Repository

Text description of image043.jpg follows.

Text description of the illustration image043.jpg

Key Points:

Figure 26-40 Querying on RESOURCE_VIEW Joined with XML Tables to Retrieve Metadata

Text description of image044.jpg follows.

Text description of the illustration image044.jpg

Key Points:

7.0 XML DB Demo: Using Views to Access XML from Relational Tools

This step demonstrates how tools and products that only understand the relational view of data can access XML content managed by Oracle XML DB.

Key Points:

  1. Execute the SQL script by clicking on the 7.0 Make Views icon.

    Figure 26-42 Creating a View Using CREATE VIEW and XPath Expressions

    Text description of image047.jpg follows.

    Text description of the illustration image047.jpg

    Key Points:

    • The view is created using a simple CREATE VIEW statement that uses XPath expressions to map text nodes or attribute values in the XML document to columns declared in the CREATE VIEW statement.
    • This example creates a PURCHASE_ORDER_MASTER_VIEW that contains one row for each document in the PURCHASEORDER table.

    Figure 26-43 Creating Purchase_Order_Master_View with one Row for Each Document in PurchaseOrders Table

    Text description of image048.jpg follows.

    Text description of the illustration image048.jpg

    Key Points:

    • Relational views can also be used to expose the members of a collection of elements as a set of rows.
    • This example creates a view called PURCHASE_ORDER_DETAIL_VIEW that exposes the contents of the lineitem elements as a set of rows. The view will contain one row for each lineitem element in the PURCHASEORDER table.
    • The first step uses the extractValue() function to generate an XML Fragment from each document in the PURCHASEORDER table. An XML Fragment is an XML document containing multiple root level nodes. In this case the XML Fragment will consist of a set of lineitem nodes. The fragment will contain one root level node for each member of the lineitems collection.
    • The next step uses the XMLSequence() function to create a separate row from each of the root level nodes in the Fragment.
    • The final step is to use the SQL TABLE operator to turn the set of rows into a table that can be used in the FROM clause of a SELECT statement.
    • There is an implicit correlated join between the PURCHASEORDER table and the set of rows generated by the TABLE operator.
  2. Close the SQL*PLUS window by typing QUIT at the SQL> prompt.

7.1 Relational Views of XML Act Like Other Views

This step demonstrates that relational views over XML look and behave like relational views over other data.

  1. Execute the SQL script by clicking on the 7.1 Query Views icon.

Figure 26-44 Querying XMLType Views Using Standard SQL

Text description of image049.jpg follows.

Text description of the illustration image049.jpg

Key Points:

8.0 XML DB Demo: Accessing Content Using DBUriServlet; Transforming Content Using XSL

This step demonstrates both how you can use DBUriServlet to access content using a Schema/Table metaphor. This also shows Oracle XML DB's ability to perform XSL transformations.

  1. Click the 8.0 DBUri and XSL Examples icon to launch Internet Explorer. If prompted for a username and password enter the database user's username and password.

    This launches Internet Explorer and uses a Repository-based URL to display the contents of the document "ADAMS-20011127121040988PST.xml". The URL uses Oracle XML DB's HTTP Server to display the content based on a resource in Oracle XML DB Repository.

  2. Click Favorites, and then click XML DB Basic Demo

    This displays a set of internet shortcuts used during the next phase of the demonstration.

    Figure 26-46 Launching Internet Explorer and a Repository-Based URL to Display XML Content

    Text description of image051.jpg follows.

    Text description of the illustration image051.jpg

    Key Points:

    • The content has been displayed based on a URL that uses a Folder/File metaphor to identify the resource that points at the required content.
  3. Do not close the Browser window at this point.

8.1 PurchaseOrder Raw XML

This step demonstrates Oracle XML DB's DBUriServlet.

See Also:

Chapter 12, "Creating and Accessing Data Through URLs"

  1. Open the XML DB Basic Demo item in the Favorites menu and select item 8.1 PurchaseOrder Raw XML. This displays the same Purchase Order document. However this document is identified using a DBURI-based path similar to the following:

    http://mdrake-lap:8080/oradb/SCOTT/PURCHASEORDER/ROW /PurchaseOrder[Reference="ADAMS-20011127121040988PST"] ?contenttype=text/xml

    Figure 26-47 Using DBUriServlet and DBUriType to Select Rows from an XML Document, Based on a URL.

    Text description of image052.jpg follows.

    Text description of the illustration image052.jpg

    Key Points:

    • The DBUriServlet leverages the DBUriType feature of Oracle XML DB. The DBUriType allows a row in a table to be identified using a URL which consists of a Schema, Table, Row and Column. XPath like syntax allows the URL to be extended to subset which rows in the target table match the URL.
      • The DBUriType returns the selected row or rows as an XML document.
      • The DBUriServlet leverages Oracle XML DB's native HTTP capabilities to allow a Browser to use a DBUri to access any row in the database.
    • This example shows accessing a row in the PurchaseOrder XMLType table using a DBUri. The URI consists of the following components:
      • /oradb: The default mount point for the DBUriServlet
      • /SCOTT: The database schema name
      • /PURCHASEORDER: The table name
      • /ROW: The default Row separator
      • /PurchaseOrder: The root node of the document in question
      • [Reference="ADAMS-20011127121040988PST"]: An XPath expression that determines which row or rows should be returned.
      • ?contenttype=text/xml: The contenttype parameter allows the developer to specify the MIME type to be returned to the Browser.
    • For an XMLType table or view, the DBUriServlet allows an XPath expression to be used to determine which rows in the table are returned. This is very similar in functionality to the W3C XPOINTER Recommendation.
    • For a Relational table or view the DBUriServlet allows an XPath-like expression, based on the columns in the table, to determine which rows should be included in the resulting document.
  2. Do not close the Browser window at this point.

8.2 Using Standard XSL Style Sheets to Transform XML Documents to HTML

This step shows a Standard style sheet that can be used to transform the PurchaseOrder document from XML to HTML.

  1. Open the XML DB Basic Demo item in the Favorites menu and select item 8.2 PurchaseOrder XSL Style sheet. This displays an XSL style sheet that can be used with the Purchase Order XML documents.

    Figure 26-48 Style Sheet for use with PurchaseOrder XML Documents

    Text description of image053.jpg follows.

    Text description of the illustration image053.jpg

    Key Points:

    • Most end-users do not want to deal with XML. They want to see information formatted into HTML The standard mechanism for converting an XML document into HTML is a Style sheet, compliant with the W3C XSLT Recommendation.
    • The Style sheet is a standard W3C XSL Style sheet. There is nothing Oracle-specific about this Style sheet.
    • To create HTML from XML, an XSLT processor is required. The processor takes the XML, and the instructions contained in the Style sheet and uses them to generate HTML.

      XSL allows display logic to be separated from processing logic. Different Style sheets can be used to format a given XML document different ways. For instance one Style sheet could format a document for display in a PC Browser, another Style sheet could format the same document for display on a WAP-enabled phone.

    In this example the Style sheet was loaded into Oracle XML DB Repository so that the database can perform the XSLT processing.

  2. Do not close the Browser window at this point.

8.3 Transforming PurchaseOrder Using XSLT

This step shows Oracle XML DB's Style sheet processor being used to transform a PurchaseOrder document from XML into HTML.

See Also:

Chapter 6, "Transforming and Validating XMLType Data"

Key Points:

  1. Open the XML DB Basic Demo item in the Favorites menu and select item 8.3 PurchaseOrder XSL Transform This displays the result of transforming the PurchaseOrder document with the XSL style sheet.

    Figure 26-49 Transforming the XML PurchaseOrder Document Using the XSL Style sheet

    Text description of image055.jpg follows.

    Text description of the illustration image055.jpg

    Key Points:

    • Style sheet processing is performed by XSLT processor incorporated into the database.
    • The Stylesheet processor can be invoked from DBUriServlet by supplying the transform=parameter as part of the URL. The value of the transform parameter is a URL that identifies the Style sheet to be used when performing the transformation.
    • The XSLT processor can also be invoked from SQL using XMLType's transform() method or the SQL xmltransform() function. The transformation is performed by Oracle XML DB XSLT processor at the database level.
    • Style sheet processing is able to leverage Oracle XML DB optimizations such as the Lazily Loaded DOM. This makes XSLT processing much more efficient.
    • The preceding example includes all of the information from the target document. However image generated is a summary document based on XSLT transformation of XML documents.
      • In a conventional system, each document required would have to parsed, converted into a DOM and then processed.
      • With Oracle XML DB, assuming the summary did not contain information from the lineItem elements, these would never be loaded as part of the XSLT processing.
  2. Do not close the Browser window at this point.]

8.4 Creating XMLType Views with SQL

This step introduces you to SQL/XML (SQLX) operators and functions used to create XMLType views and generate XML from an SQL query.

See Also:

Chapter 11, "XMLType Views"

  1. Open the XML DB Basic Demo item in the Favorites menu and select item 8.4 DEPTVIEW Definition.
  2. This displays an HTML page showing the definition of the DEPTVIEW XMLType view.

    Figure 26-50 HTML Page Showing XMLType View DEPTVIEW

    Text description of image056.jpg follows.

    Text description of the illustration image056.jpg

    Key Points:

    • SQL/XML is an ANSI/ISO standard. It falls into two main sections.
      • The first provides functions and operators for inserting, querying and updating XML documents as part of a SQL operation, and for including an XML document, or parts of an XML document in the resultset returned by a SQL operation
      • The second provides functions for generating an XML document from a query against relational tables.
    • The SQL/XML standard is being developed by Oracle, IBM, Microsoft, and other interested parties.
    • This example shows how to use SQL/XML functions to generate an XMLType view, which provides a persistent XML View of the contents of the EMP and DEPT tables in the SCOTT sample schema.
    • The view will consist of a collection of Department nodes. Each Department will contain elements DNAME and LOC, as well as collection of Employee nodes containing the details of each employee in the department.
    • The SQL/XML operators have been designed to make it easy to generate any shape of XML from a SQL result set.
    • XMLForest() is so named because it contains a collection of "Trees".
    • Unlike other vendors, Oracle takes the SQL /XML operators into account when determining which plan to use to resolve a query. This may result in the query plan selected when generating XML to be different from the query plan selected when generating the equivalent tabular resultset.
    • Other vendors implement SQL/XML by creating a DOM based on the SQL/XML operators, and then executing a conventional relational query, forcing the result into the DOM, and then printing the DOM. This is much less efficient for a number of reasons:
      • The database is not able to consider the shape of the required output when determining the query plan
      • The tabular result set has to be forced into a DOM structure before the required result set can be generated. This results in significant memory and processing overhead.
    • Do not close the Browser window at this point.

8.5 Displaying DEPTVIEW Raw XML Using DBUriServlet

This step shows how to use DBUriServle to display DEPTVIEW contents.

  1. Open the XML DB Basic Demo item in the Favorites menu and select item 8.5 Display DEPTVIEW. This displays the contents of the DEPTVIEW XMLType view.

    Figure 26-51 DEPTVIEW Contents

    Text description of image057.jpg follows.

    Text description of the illustration image057.jpg

    Key Points:

    • The XMLType view exposes DEPT and EMP as a single XML document.
    • There is one <ROW> element in the generated document for each row selected from DEPT table.
    • The shape of the XML document is defined by the SQL/XML operators used in the view definition.

8.6 Transforming DEPTVIEW From XML to HTML Using a Style Sheet

This step shows how to use a Style sheet to transform a PurchaseOrder document from XML to HTML.

  1. Open the XML DB Basic Demo item in the Favorites menu and select item 8.6 DEPTVIEW style sheet This displays an XSL style sheet that can be used with view DEPTVIEW.

    Figure 26-52 XSL Style Sheet for Use with DEPTVIEW

    Text description of image059.jpg follows.

    Text description of the illustration image059.jpg

    Key Points:

    • The style sheet is a standard W3C compliant XSLT style sheet. There is nothing Oracle-specific about it.

    Do not close the Browser window at this point.

8.7 Displaying the Transformed DEPTVIEW After XSL Transformation

This step shows how you can use a Style sheet to transform a PurchaseOrder document from XML to HTML.

  1. Open the XML DB Basic Demo item in the Favorites menu and select item 8.7 DEPTVIEW with XSL Transformation. This displays the result of transforming the PurchaseOrder document with the XSL style sheet.

    Figure 26-53 A Style Sheet for Transforming PurchaseOrder Documents from XML to HTML

    Text description of image061.jpg follows.

    Text description of the illustration image061.jpg

    Key Points:

    • Oracle XML DB makes it easy to display the contents of relational tables such as DEPT and EMP as an HTML document.
    • Use the SQL/XML operators to create an XMLType view that format the contents of the relational tables as an XML document then apply an XSLT style sheet to transform the XML document into HTML.
    • No procedural coding, servlets, or other application components need be created or installed to achieve this functionality.
  2. Close the Browser window.

9.0 XML DB Demo: OracleText Examples

This step illustrates how OracleText functionality can be applied to XML content stored in Oracle XML DB using Structured Storage techniques.

  1. Execute the SQL script by clicking on the 9.0 Oracle Text Examples icon.

    Figure 26-54 Searching a PurchaseOrders Table by Using Oracle Text's contains() Operator

    Text description of image062.jpg follows.

    Text description of the illustration image062.jpg

    Key Points:

    • Oracle XML DB allows Oracle Text indexes to be created on XML content stored in the database using Structured Storage Techniques.
    • Two kinds o OracleText indexes are allowed:
      • ctxsys.ctxxpath. This can be used to speed up the existsNode() function.
      • ctxsys.conte. This allows for a full text search on XML content.
    • By default existsNode() looks for a B-Tree or function-based index and then is used to resolve the query. If no such index exists it performs a functional evaluation of each document in the table to see if it contains a node that matches the supplied XPath expression.
    • If a ctxsys.ctxxpath index has been created then existsNode() uses this index as a primary filter when resolving an XPath expression that cannot be resolved with a B-Tree or function-based Index. This is much faster than performing a functional evaluation of every document in the table.
    • The example shows creating a full text (ctxsys.context) index on the PURCHASEORDER table and then using the Oracle Text contains() function to perform a Text-based search over the PurchaseOrder XML documents.
  2. Close the SQL*PLUS window by typing QUIT at the SQL> prompt.

    See Also:

    Chapter 7, "Searching XML Data with Oracle Text"