Oracle XML DB

Basic Demonstration

ORAC LE XML DB DEMO – SC RIPT (9.2.0. 2.0)
Pre-requisites ...................................................................................................................................................................................................4 Non Oracle Software...............................................................................................................................................................................4 Oracle Software.........................................................................................................................................................................................4 Installing the Demonstration......................................................................................................................................................................5 Installation Parameters ............................................................................................................................................................................5 Database, Oracle Net Services and XML DB Configuration.......................................................................................................6 XML DB protocol configuration.........................................................................................................................................................7 TNS Listener Configuration..................................................................................................................................................................8 Verify XML DB protocol configuration and connectivity ............................................................................................................9 Verify SQL*NET and XML DB Configuration..............................................................................................................................9 Configuring the demonstration installation.....................................................................................................................................11 Completing the demonstration installation......................................................................................................................................12 What is the Oracle XML Database? .......................................................................................................................................................13 Oracle XML DB Major Features.............................................................................................................................................................14 XMLType..................................................................................................................................................................................................15 XML Schema...........................................................................................................................................................................................18 Namespaces.........................................................................................................................................................................................18 XML Schema and Namespaces......................................................................................................................................................18 Registering an XML Schema...........................................................................................................................................................19 DOM Fidelity......................................................................................................................................................................................20 Annotating an XML Schema..........................................................................................................................................................20 Identifying and Processing Instance Documents......................................................................................................................20 Structured Vs Unstructured Storage.............................................................................................................................................21 XML / SQL Duality ..............................................................................................................................................................................23 SQL/XML ...........................................................................................................................................................................................23 XPath and Query Re-write ..............................................................................................................................................................25 XML DB Repository..............................................................................................................................................................................27 The Oracle XML DB Protocol Architecture..............................................................................................................................31 Programmatic Access.............................................................................................................................................................................32 Oracle XML DB performance.................................................................................................................................................................33 XML Storage Requirements.................................................................................................................................................................33 XML Memory Management ................................................................................................................................................................33 XML Parsing Optimizations................................................................................................................................................................34 Node Searching Optimizations...........................................................................................................................................................34 Page 1 of 116 January 31, 2003

Oracle XML DB

Basic Demonstration

XML Schema Optimizations ...............................................................................................................................................................34 Load Balancing ........................................................................................................................................................................................34 Non-Native Code...................................................................................................................................................................................35 Type Conversions ...................................................................................................................................................................................35 XML Manageability .....................................................................................................................................................................................36 Performing the demonstration.................................................................................................................................................................37 0.1 Initial Setup (Run Once) ................................................................................................................................................................38 0.2 Reset Demo.......................................................................................................................................................................................38 1.0 XML DB Repository.......................................................................................................................................................................39 1.1 Make Directories..............................................................................................................................................................................42 1.2 Oracle XML DB Protocol Architecture ....................................................................................................................................45 1.3 Load Configuration Files ...............................................................................................................................................................46 2.0 Show XML Schema.spp.................................................................................................................................................................47 Creating and Editing an XML Schema.........................................................................................................................................47 Annotating an XML Schema..........................................................................................................................................................51 2.1 Register Schema................................................................................................................................................................................53 2.2 Show Objects ....................................................................................................................................................................................54 3.0 Load Sample Data............................................................................................................................................................................56 3.1 Add Constraints................................................................................................................................................................................59 3.2 Duplicate Reference ........................................................................................................................................................................61 3.2 Invalid User .......................................................................................................................................................................................62 3.3 Invalid Document............................................................................................................................................................................63 4.0 Simple Queries (1)............................................................................................................................................................................65 4.1 Simple Queries (2)............................................................................................................................................................................67 4.2 Explain Plan (1) ................................................................................................................................................................................69 4.3 Create XML Indexes.......................................................................................................................................................................73 4.4 Explain Plan (2) ................................................................................................................................................................................75 5.0 BLAKE-2002100912333601PDT.XML....................................................................................................................................79 5.1 Show Document (1) ........................................................................................................................................................................81 5.2 Edit Document.................................................................................................................................................................................82 5.3 Show Document (2) ........................................................................................................................................................................85 5.4 Update Document ...........................................................................................................................................................................86 5.5 BLAKE-2002100912333601PDT.XML....................................................................................................................................88 6.0 Resource View Queries (1)............................................................................................................................................................89 6.1 Resource View Queries (2)............................................................................................................................................................93 7.0 Make Views........................................................................................................................................................................................96 Page 2 of 116 January 31, 2003

Oracle XML DB

Basic Demonstration

7.1 Query Views......................................................................................................................................................................................98 7.2 Make XML View ........................................................................................................................................................................... 100 8.0 DBURI and XSL Examples....................................................................................................................................................... 103 8.1 Content of DEPT Table......................................................................................................................................................... 104 8.2 Department number for CHICAGO and NEW YORK.............................................................................................. 105 8.3 Purchase Order Raw XML .................................................................................................................................................... 106 8.4 Department View Raw XML................................................................................................................................................ 108 8.5 Purchase Order Style sheet .................................................................................................................................................... 109 8.6 PurchaseOrder with XSL Transformation........................................................................................................................ 110 8.7 Department View style sheet ................................................................................................................................................ 112 8.8 Department View with XSL Transformation................................................................................................................... 113 9.0 OracleText examples.................................................................................................................................................................... 114 Appendix I: Configuring a Local Listener..................................................................................................................................... 116

Page 3 of 116

January 31, 2003

com. This demonstration can be run against a remote database.Oracle XML DB Basic Demonstration PRE-REQUISITES Before starting to install the demonstration it is recommended that the following software is installed: NON ORACLE SOFTWARE • • • XMLSpy – XML Spy is a XML Schema editor from Altova.0. Oracle 9i Database release 9. Oracle Client (SQL*PLUS and Oracle Net Services) 9. You cannot use any version of Netscape for this demonstration. Internet Explorer 5. • ORACLE SOFTWARE • • Page 4 of 116 January 31. Microsoft Windows 2000 with Service pack 1.2. Windows Scripting is used to create the shortcuts that are used to launch each step in the demonstration and to copy files from the install directory structure to the demonstration directory structure. If you do not have a license for this product you can download an evaluation copy from http://www.5 has a number of serious caching issues which will mean that some sections of the demonstration will not work as expected. This is used by the installation script to process the configuration files.asp?URL=/downloads/sample.asp?url=/downloads/sample. Microsoft Office 2000 or Microsoft Office XP.com/downloads/default. Also. At the time of writing the latest version of this software can be downloaded from http://msdn.microsoft.asp? url=/msdn-files/027/001/733/msdncompositedoc. 2003 .0.6 or later.0 or later.2. Microsoft Windows Scripting Technologies version 5. • Microsoft DOM control and XML Parser for VBScript. The demonstration makes use of Microsoft Word’s support for WebDAV. At the time of writing the latest version of this software can be downloaded from http://msdn.microsoft. however SQL*PLUS and Oracle Net Services must be installed on the client machine.xml Make sure to restart windows after installing the latest version of Windows Scripting.altova. You can verify the version of Windows Scripting installed on your machine by opening a Windows Command Prompt session and typing the command cscript at the command prompt. Notepad or WordPad cannot be substituted as they are not WebDAV enabled.asp?url=/msdnfiles/027/001/766/msdncompositedoc.0 with the latest service packs is strongly recommended.2.0 or later.xml • Microsoft Internet Explorer 6.2.com/downloads/default.

A TNS alias that will establish Oracle Net Services connections to the target database and listener. The hostname or IP address of the machine that is hosting the target TNS Listener.zip into a folder of your choice. Ensure that there are no space characters in the path that leads to the basicDemo folder. The port numbers used by the Oracle XML DB protocols to service HTTP and FTP requests.Oracle XML DB Basic Demonstration INSTALLING THE DEMONSTRATION To install the XDB basic demo unzip the file XDBBasicDemo. Page 5 of 116 January 31. After unzipping this file the target folder should contain a subfolder called basicDemo . The default values are 8080 (HTTP). The name of the target TNS Listener. by default this is LISTENER The port number used by TNS Listener to service TCP based SQL requests. and 2100 (FTP). INSTALLATION PARAMETERS The following information is required in order to correctly install and configure the XML DB Demonstration • • • • • • • • The path to the local (client-side) ORACLE_HOME. The SERVICE_NAME of the target database instance. The default for this value 1521. This user must have been granted connect and resource privileges. 2003 . The username and password that will be used when giving the demonstration. Open a Windows Command Prompt session in this directory.

Open a Windows Command Prompt session.sql script Page 6 of 116 January 31.Oracle XML DB Basic Demonstration DATABASE . ORACLE NET SERVICES AND XML DB CONFIGURATION Before starting the installation verify that Oracle Net Services. 2003 . This script must be run as user SYS Fig I.sql. Start SQL*PLUS. running the xdbConfiguration. and set the working directory to be basicDemo/Install . FTP and HTTP are all correctly configured using the following steps. and the script xdbConfiguration.

XML DB PROTOCOL CONFIGURATION If the port numbers shown are not the required values the PL/SQL package xdb_configuration can be used to reconfigure the ports as follows For FTP: SQL> call xdb_configuration.oracle. After resetting the port numbers validate the new numbers have been accepted executing the following statement: SQL> select xdburitype(’/sys/databaseSummary. 2003 .drake. <Database Name ="ORCL9202" HTTP="8080" FTP="2100"> <Services> <ServiceName >ORCL9202.com</ServiceName > </Services> <Hosts> <HostName >MDRAKE-LAP</HostName > </Hosts> </Database> Note that the above example shows the default XDB port numbers which are set when XML DB is installed and may not match the values in your environment.setHTTPport(nnnn) 2 > / In the above examples nnnn represents the target port number. This should look like the following example.getXML() 2 > from dual 3 > / Page 7 of 116 January 31.xp.xml’). The chosen FTP port number and HTTP port number cannot be the same value and they cannot be in by any other service on the system. In general the selected port numbers should not be privileged port numbers (0-1023).mark.setFTPport(nnnn) 2 > / For HTTP: SQL> call xdb_configuration.Oracle XML DB Basic Demonstration If XML DB is correctly installed this should cause the XML DB configuration summary document to be displayed.

0 or greater.2.ora file is located in the directory <ORACLE_HOME>/network/admin. The listener. 2003 .Oracle XML DB Basic Demonstration TNS LISTENER CONFIGURATION Display the current status of the TNS Listener using the command lsnrctl status .0.ora file). Verifying Listener Configuration If the database is running on a remote machine. Page 8 of 116 January 31.ora file can also be used to verify the port number being used for Oracle Net Services. If the database has not registered with the listener make check whether a Local Listener has been configured. If a LOCAL_LISTENER entry has been configured ensure that it references the correct listener. Executing the command should generate output similar to the following: Fig II.ora file used to configure the database. Verify that the Listener version is 9. See Appendix I for details on how to add a local_listener entry to the init. This will ensure that the Oracle XML DB protocols connect to the correct TNS Listener. the command must be executed from a Windows Command Prompt session or telnet session attached to the remote machine.1.xml document. Verify that the that the following items are true • • The target listener is servicing Oracle Net Services requests on port 1521 The target listener is servicing HTTP and FTP services on the ports identified in the databaseSummary. If the output from the lsnrctl status command does not include entries describing FTP and HTTP services then the database has not registered with this listener. Manual inspection of the listener. If the TNS Listener is not running on default port of 1521. a LOCAL_LISTENER parameter must be added to the init.

Make a note of the hostname. Verifying Protocol Configuration from SQL*PLUS Page 9 of 116 January 31. 2003 . To disable HTTP and FTP Services for a given database instance set the port numbers to zero.sql script on each database instance Use the xdb_configuration package to assign unique FTP and HTTP ports to each database instance. Multiple listeners can run on a given server. If multiple database instances are running on a given server each must be configured with HTTP and FTP port numbers that are unique to the server machine. use the lsnrctl status command to check that each database instance has been re-configured to service unique FTP and HTTP port numbers. VERIFY SQL*NET AND XML DB CONFIGURATION Verify that the Oracle Net Services. Once all of the database instances have been configured with unique port numbers. In order to ensure that the port number are unique execute the xdbConfiguration. HTTP port number and FTP port number.Oracle XML DB Basic Demonstration VERIFY XML DB PROTOCOL CONFIGURATION AND CONNECTIVITY Confirm that there are no HTTP or FTP port conflicts with other database instances running on the same host. FTP and HTTP protocols are configured as expected using the following procedure. Verify which HTTP and FTP ports that are current configured for the target database by connecting to the database using SQL*PLUS as shown below. Fig III. The following example assumes that the TNS alias ORCL92 will establish a connection to the target database. A given listener can service HTTP and FTP requests for multiple database instances.

xml document that was accessed using SQL. 2003 . Page 10 of 116 January 31.xml document returned by HTTP Server should be identical to the one that was accessed via SQL. Verifying Protocol Configuration from FTP If the FTP Protocol is configured correctly the databaseSummary. The hostname and FTP port number used in the open command should be taken from databaseSummary.xml document returned by the FTP Server should be identical to the one that was accessed via SQL. Verify the HTTP configuration using the browser as shown below. Fig IV. The browser will prompt for a username and password. the open command has to be used to establish the connection to server. Verifying Protocol Configuration from HTTP If the HTTP Protocol is configured correctly the databaseSummary. Since the target FTP Server is not running on the default FTP port of 21.Oracle XML DB Basic Demonstration Verify the FTP configuration by connecting to the target database via FTP as shown below. The hostname and HTTP port number specified in the address should be taken from databaseSummary. Fig V. Enter the name and password of the database user that will be used when running the demonstration.xml document that was accessed using SQL.

2003 . Close the Command Prompt session. verify that the file still contains well formed XML by opening it in Internet Explorer. Page 11 of 116 January 31.2. This folder contains a folder called install.0. After editing the installationParameters. Start by editing this file 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: <localConfiguration> <shortCutFolderName >9. The install folder contains a file called install. Special attention should be taken to ensure that the values for <oracleHome>. <oracleSID>.vbs.xml file.xml which drives the installation process. The install folder also contains a file called installParameters.0 Demo</shortCutFolderName > <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 > </localConfiguration> Change the contents of the file to reflect your environment. This file contains the set of arguments required to tailor the installation. <httpPort> and <ftpPort> are correct.Oracle XML DB Basic Demonstration CONFIGURING THE DEMONSTRATION INSTALLATION Unzipping the installation file creates a folder called basicDemo.2. which will install the demonstration. Save the file.

2003 . Installation Dialogs At the end of the installation process the script will report installation complete.vbs script. If any of the values supplied to the installation procedure were incorrect the demonstration can be re-installed by editing installParameters. Start the installation script by ‘double-clicking’ the install. Click OK to complete installation of the demonstration. Fig VI.xml file and then re-executing the install. The script will prompt for confirmation before starting the configuration process: Click OK to configure the demo.Oracle XML DB Basic Demonstration COMPLETING THE DEMONSTRATION INSTALLATION Open a Windows Explorer session and navigate to the Install folder. Page 12 of 116 January 31. At this point the demonstration is installed and ready to run.vbs script.

XML-specific memory management and optimizations. including XPath and SQL/XML. allowing XML operations on SQL data and SQL operations on XML content. An simple. • • • • • • • XML/SQL duality. It delivers new methods for navigating and querying XML content stored inside the database and introduces an XML Repository for managing XML document hierarchies. The ability to absorb a standard W3C XML Schema data model into the Oracle database. The ability to bring the enterprise class management capabilities of the Oracle database.Oracle XML DB Basic Demonstration WHAT IS THE ORACLE XML DATABASE ? Oracle XML DB is the term used to describe technology in the Oracle 9i Release 2 database that delivers highperformance storage and retrieval of XML.to bear on XML content. 2003 . availability. scalability and unbreakable security -. adding all of the functionally associated with native XML databases • • • A native XML data-type that is used to store and manage XML documents. industry-standard APIs that allow programmatic access and update of XML content from Java. you get all the advantages of relational database technology and XML technology at the same time. Page 13 of 116 January 31. delivering all of the functionality associated with a native XML database. content-orientated. A set of methods and SQL operators which allow XML operations to be performed on XML content. HTTP and WebDAV making it possible to move XML content in and out of the Oracle database. Oracle XML DB provides a storage-independent. protocols including FTP. Native database support for industry-standard. -. in addition to all of the functionality provided by the most sophisticated and complete relational database currently available.reliability. With Oracle XML DB. content-independent and programming-language-independent infrastructure to store and manage XML data. Oracle XML DB delivers the following functionality: Oracle XML DB extends the Oracle relational database. Multiple. This technology extends the popular Oracle relational database. ‘C’ and PL/SQL. Industry-standard methods for accessing and updating XML. light-weight XML Repository that allows XML content to be organized and managed using a file / folder / URL metaphor.

replication. to be used to query and update XML documents that are stored in an Oracle database. A URL uses a path through a folder hierarchy to identify a document. data integrity. Here are the major features of Oracle XML DB: Page 14 of 116 January 31. On the fact of it these hierarchical metaphors are not easy to map in the relational model. 2003 . Examples of this include Uniquely identifying an XML document: The standard way of identifying an XML document is via a URL. With a relational database the table-row metaphor is used to locate content.Oracle XML DB Basic Demonstration ORACLE XML DB MAJOR FEATURES Any database that is going to be used manage XML must be capable of more than simply persisting XML documents. Primary-Key Foreign-Key relationships are used to define the relationships between content. It must provide standard database features like transaction control. security and scalability. availability. These operators allow XML centric metaphors. Accessing and updating the content of an XML document. update and search XML content in an XML centric manner. Content is accessed and updated using a table-row-column metaphor. Oracle XML DB addresses these challenges by introducing new SQL operators and methods that provide direct support for the hierarchical nature of XML. The XPath standard uses a path through the XML document’s node hierarchy to identify or access the contents of part of an XML document. such as XPath expressions and URLs. The standard ways of addressing and updating content is via WC3 standards like XPath. URLs and XPath expressions are both intrinsically hierarchical in nature. reliability. It must also provide the features required to efficiently index. query. Defining relationships between XML documents: The standard way of defining a relationship between two documents is via URL based standards like XLink. One of the major challenges with using a traditional relational database to manage XML content is the hierarchical nature of the XML world.

• Page 15 of 116 January 31. 2003 . By default. The XMLType data-type can be used just like any other data-type. Structured-storage decomposes or ‘shreds’ the content of the XML document and stores it as a set of SQL objects rather than simply storing the document as text in CLOB. Constraining the XMLType to an XML Schema provides the option of storing the content of the document using structured-storage techniques.Oracle XML DB Basic Demonstration XMLTYPE XMLType is a native server data-type that allows the database to understand that a column or table contains XML. in the same way that the DATE data-type allows the database to understand that a column contains a date. An XMLType table or column can be constrained to an XML Schema. or a relational view that includes an XMLType column. Since the contents of the table or column are conformant with a known XML structure. Oracle XML DB can use the information contained in the XML Schema to provide more intelligent query and update processing of the XML. Since XMLType is an object type. Creating an XMLType view. it is also possible to create a table of XMLType. XMLType also provide methods that allow common operations such as schema validation and XSL Transformations to be performed on XML content. and when defining and calling PL/SQL procedures and functions. The XMLType data type can also be used when defining views. allows Oracle XML DB to be used to expose content stored relational tables and external data sources as XML documents. It can be used when declaring PL/SQL variables. an XMLType table or column can contain any well formed XML document. The object-model used to store the document is automatically derived from the contents of the XML Schema. It can be used when creating a column in a relational table. Constraining a column or table to an XML Schema has a number of advantages associated with it: • • The database will ensure that only XML documents that validate against the XML Schema can be stored in the column or table. This allows for maximum flexibility in terms of the shape of the XML structures that can be stored in a single table or column and the highest rates of ingestion and retrieval. The content of the document is stored as XML text using the CLOB data type.

An XML object in an XMLType table.Oracle XML DB Basic Demonstration The following diagram shows how XML can be stored and retrieved using Oracle XML DB and the XMLType data type: XML can be stored one of two ways: An XMLType column in a relational table. 2003 . Non Schema based XML is always stored as CLOB. Relational and external data can be exposed as XML using views. checking whether or not a particular node exists in the XMLType ( existsNode() ). The view can be a relational view containing a column of XMLType or can be a XMLType View. It also provides a number of XML specific methods which can operate on XMLType objects. The methods provided by XMLType provide support for common operations like extracting a subset of the nodes contained in the XMLType ( extract() ). XMLType storage options The XMLType data-type provides constructors that allow an XMLType to be created from a VARCHAR or CLOB data-type. Schema based XML can be stored as a CLOB or as a set of objects. Page 16 of 116 January 31. XML Sch e ma Table Non Schema| Based XML Schema Based XML Schema Based XML View Non Schema Based XML CLOB Storage Object Relational Storage Relational Tables External Data Sources Fig I. validating the contents of the XMLType against an XML Schema ( schemaValidate() ). and performing an XSL Transformation ( transform() ).

2003 . The constructors of the XMLType allow XMLType to be created from VARCHAR and CLOB. creating a relational table with a column of XMLType Page 17 of 116 January 31. Fig II.Oracle XML DB Basic Demonstration The following screen shot shows creating a simple table w ith an XMLType column and then performing insert and query options against the table. New SQL operators make it possible to perform SQL queries over XML content. The XMLType data type can be used just like any other data type. Inserting into a table with an XMLType column is like inserting into any other table.

This provides for strong typing of the elements and attributes. and certain semantics of a set of XML documents. An XML namespace is a collection of names. If the XML Schema does not specify a targetNamespace. or vocabulary. Oracle XML DB supports all of constructs defined by the XML Schema standard. default values. XML Schema is a W3C standard for specifying the structure. all elements and types defined by the schema are associated with this namespace. attribute.org/TR/xmlschema-0/. The XML Schemas in question are identified on a namespace by namespace basis using attributes defined in the WC3 XMLSchema-Instance namespace. nesting. etc). which is compliant with the vocabulary defined by the “Schema for Schemas ”.w3. This implies that any XML document that contains these elements and types must identify which namespace the elements and types are associated with. often referred to as the “Schema for Schemas”. This XML Schema provides the definition. Page 18 of 116 January 31.org/2001/XMLSchema-instance" Once the XMLSchema-instance namespace has been declared the required set of XML Schemas is defined by adding schemaLocation and noNamespaceSchemaLocation attributes to the root element of the document. Since the two objects are in different XML Schemas they cannot be treated as being the same item. The XML Namespace specification defines a mechanism which accomplishes this. all elements and types defined by the schema are associated with the NULL namespace. The XMLSchema-Instance namespace is declared by including a variant of the following namespace declaration in the root element of the instance document: xmlns:xsi="http://www. XML SCHEMA AND N AMESPACES The targetNamespace attribute is used to define the namespace associated with a given XML Schema. An XML Schema is an XML document. N AMESPACES It is possible for two different XML Schemas to use the same name when defining an object (element. 2003 . the term “instance document” is often used to describe an XML document that conforms to a particular XML Schema. mandatory content. The W3C Schema Working Group publishes an XML Schema. making is possible for the schema designer to create complex objects from the base data types defined by the XML Schema language. The XML Schema language defines 47 scalar data types. The XMLType data type provides the methods isSchemaValid() and schemaValidate() that allow Oracle XML to use an XML Schema in this manner. This means that an instance document must identify which XML Schema a particular node is based on. If an XML Schema specifies a targetNamespace. except for redefines .Oracle XML DB Basic Demonstration XML SCHEMA Comprehensive support for the W3C XML Schema standard is one of the key features of Oracle XML DB. The W3C XML Schema vocabulary also includes constructs that can be used to define ordering. The attribute is included in the definition of the ‘schema ’ element. The XML Schema standard is described by the W3C in http://www. The XML Schema standard also defines a mechanism that allows an instance document to identify which XML Schemas are required in order to process or validate the document.w3. repeated sets. An XML Schema document uses the vocabulary defined by W3C XML Schema Working Group to create a collection of type definitions and element declarations which declare a shared vocabulary that describe the contents and structure of a new class of XML documents. simple type. complex type. content. The most common usage of an XML Schema is as a mechanism for validating that an instance documents are conformant with a given XML Schema. The XML Schema standard also supports the use of object-oriented techniques like inheritance and extension. etc. of the XML Schema language. identified by a URI reference which are used in XML documents as element types and attribute names. Since an XML Schema is used to define a class of XML documents. In order to use this mechanism the instance document must first declare the XMLSchema-instance namespace.

REGISTERING AN XML SCHEMA Before Oracle XML DB can make use of the information contained in an XML Schema. 2003 .e. This hint is often referred to as the “Document Location Hint” The noNamespaceSchemaLocation attribute is used to identify any XML Schema that did include a targetNamespace declaration. Page 19 of 116 January 31. Each entry consists of a pair of values. The URL a used internally as a unique key used to identify the XML Schema. At no point does Oracle XML DB require direct access to the URL specified when registering the XML Schema. The default tables created by registering an XML Schema are XMLType tables. When an instance document is loaded in the Oracle XML DB repository. typically in the form of a URL. Oracle XML DB can use the information contained in an XML Schema to derive an object model that allows XML content that is compliant with the XML Schema to be decomposed and stored in the database as a set of objects. which describes where to find to the appropriate XML Schema. When an XML Schema is registered with the database. the content of the document will be stored in the default table. a default table is created for each global element defined by the XML Schema.Oracle XML DB Basic Demonstration The schemaLocation attribute is used to identify XML Schemas that included a targetNamespace declaration. The noNamespaceSchemaLocation attribute contains a hint. typically in the form of a URL. they are Object Tables. The right hand side of each pair is a hint. which describe where to find the required XML Schema. The constructs defined by the XML Schema are mapped directly into SQL Types generated using the SQL 1999 Type Framework that is part of the Oracle database.register_schema() . The left hand side of each pair is the value of the targetNamespace attribute. i. The XML Schema is registered under a URL. The schemaLocation attribute contains of one entry for each XML Schema. There can only be such XMLSchema for a given instance document. An XML Schema is registered by called the PL/SQL procedure called dbms_xmlschema. the XML Schema must be registered with the database. where each row in the table is represented as an instance of the XMLType data type.

and language-neutral interfaces that allow a program to dynamically access and update the content. If you do not specify any annotations to your XML Schema to customize the mapping.Oracle XML DB Basic Demonstration Using the SQL 1999 Type Framework to manage XML provides a number of significant benefits: • • • • • It allows Oracle XML DB to leverage the full power of the Oracle database when managing XML. By guaranteeing DOM fidelity. In order for an XML document to be recognized as an instance of the XML Schema the root element of an instance document would need to look like <PurchaseOrder xmlns:xsi=http://www. DOM. and specify how much of a document should be shredded. The XML Schema has been registered under the URL http://xmlns. and also across their SQL storage counterparts. or the Document Object Model. Oracle XML DB is able to ensure that there is no loss of information when the database is used to store and manage XML documents. Capturing the XML Schema objects as SQL Types helps share the abstractions across schemas. IDENTIFYING AND PROCESSING INSTANCE D OCUMENTS Oracle XML DB assumes that instance documents will use the W3C approved mechanism for identifying which XML Schemas they are associated with. takes place when an XML document is stored in the database. The XML Schema does not include a targetNamespace declaration.com/demo/purchaseOrder. It can lead to significant reductions in the amount of space required to store the document. is a W3C standard that defines a set of platform. 2003 . control how collections are stored in the database. It assumes that the Document Location Hint contained in an instance document will map directly to the URL that was specified when registering the associated XML Schema with the database. or ‘shredding’.oracle. It allows Oracle XML to support constructs defined by the XML Schema standard that do not easily map directly into the conventional relational model. Oracle XML DB will make certain default choices that may or may not be optimal for your application.org/2001/XMLSchema-instance xsi:noNamespaceSchemaLocation=”http://xmlns. processing instructions and mixed text.xsd”> Page 20 of 116 January 31. DOM FIDELITY Using SQL 1999 objects to persist XML allows Oracle XML DB to guarantee DOM fidelity. The Oracle XML DB schema processor recognizes a set of annotations that make it possible to customize the mapping between the XML Schema data types and the SQL data types. A NNOTATING AN XML SCHEMA Oracle XML DB provides the application developer or database administrator with control over how much decomposition. The XML Schema standard allows vendors to define schema annotations that add directives for specific schema processors. This includes maintaining the order in which elements appear within a collection and within a document as well as storing and retrieving out-of-band data like comments.com/demo/purchaseOrder.xsd. structure and style of a document.w3. Providing DOM Fidelity requires Oracle XML DB to preserve all of the information contained in an XML document. In order to provide DOM fidelity Oracle XML DB must ensure that a DOM generated from a document that has been shredded and stored in Oracle XML DB will be identical to a DOM generated from the original document. It can reduce the amount of memory required to query and update XML content.oracle. assume an XML Schema defines a global element PurchaseOrder. For example.

Structured-storage provides a number of advantages for managing XML. However trailing new lines. leading to significantly improved performance. leading to significantly reduced response times and greater throughput. Unstructured-storage provides for the highest possible throughput when inserting and retrieving entire XML documents. b-tree indexing and in-place updates. This allows in-place. XPath operations evaluated by constructing DOM from CLOB and using functional evaluations. SQL constraints are not currently available. reduced storage requirements. Provides the maximum amount of flexibility in terms of the structure of the XML documents that can be stored in an XMLType column or table. These throughput and flexibility benefits come at the expense of certain aspects of intelligent processing. Only document that conform to the XML Schema can be stored in the XMLType table or column. white space characters between tags and some data formatting may be lost The majority of update operations can be optimized using Query re-write. These advantages are at a cost of somewhat increased processing overhead during ingestion and retrieval and reduced flexibility in terms of the structure of the XML that can be managed by a given XMLType table or column. There is little that the database can do to optimize queries or updates on XML that has been stored using a CLOB data type. Changes to the XML Schema may require data to be unloaded and reloaded DOM Fidelity: A DOM created from an XML document that has been stored in the database will be identical to a DOM created from the original document. XPath based queries. When any part of the document is updated the entire document must be written back to disk. piece-wise update. SQL Constraint Support Page 21 of 116 SQL constraints are supported. including optimized memory management. January 31. Where possible. Delivers Document Fidelity: Maintains the original XML byte for byte. Limited Flexibility. XPath operations are evaluated using query-rewrite. It also provides the greatest degree of flexibility in terms of the structure of the XML that can be stored in a XMLType table or column. which may be important to some applications Structured Storage The decomposition process results in slightly reduced throughput when ingesting or retrieving the entire content of an XML document. Flexibility XML Fidelity Optimized Update Operations Optimized update operation are not possible. This can be very expensive when performing operations on large collections of documents. particularly with large collections of documents.Oracle XML DB Basic Demonstration STRUCTURED VS UNSTRUCTURED STORAGE One of the key decisions to be made when using Oracle XML DB is persist XML documents is when to use structured-storage and when to use unstructured storage. 2003 . The relevant merits of Structured and Unstructured storage are outlined in the following table Unstructured Storage Throughput Highest possible throughput when ingesting and retrieving the entire content of an XML document.

Oracle XML DB Basic Demonstration Indexing Support Text and Functional indexes. 2003 . Optimized XML operations of the Memory document require creating a Management DOM from the document Table 1: Pros and cons of XML storage options Page 22 of 116 January 31. Text and Functional Indexes. B-Tree. XML operations can be optimized to reduce memory requirements.

The first category consists of a set of operators that make it possible to query and access XML content as part of normal SQL operations. simple solutions to a number of common business problems. This means that the XML programmer can leverage the power of the relational model when working with XML content and the SQL programmer can leverage the flexibility of XML when working with relational content. The content can be easily accessed and updated using standard APIs based on DOM and XPath.htm for more information. Oracle XML DB erases the traditional boundary between applications that work structured data and those that work with semi-structured and unstructured content. It can only be accessed via specialist tools.Oracle XML DB Basic Demonstration XML / SQL DUALITY Much of the valuable information within an organization is in the form of semi-structured and unstructured data. • Relational data can quickly and easily be converted into HTML pages. The same information. The second category consists of a set of operators that provide an industry standard method for generating XML from the result of a SQL Select statement.) The SQL/XML operators fall into two categories. The information in these files is in proprietary or application specific formats.ncits. or to a program that uses Microsoft’s COM APIs.org and http://www. This provides application developers with maximum flexibility. Searching across this information is limited to the facilities provided by a crawler or full text indexing. See http://sqlx. Spatial Data. such as word processors or spreadsheets. This means that Oracle XML DB is able to provide new. 2003 . and Multimedia operations can be performed on XML Content. The XML can be transformed into other formats. XML/SQL duality means that the same data can be exposed as rows in a table and manipulated using SQL or exposed as nodes in an XML document and manipulated using techniques like DOM or XSL transformation. The access metaphor and processing techniques used are totally independent of the underlying storage format. Typically this data is contained in files stored on a file server or in a CLOB column inside a database. Text. Replacing proprietary file formats with XML allows organizations to achieve much higher levels of reuse of their semi-structured and unstructured data. SQL/XML is defined by specifications prepared by the International Committee for Information Technology Standards (Technical Committee H2). The content can be accurately described using XML Schema. • • SQL/XML Oracle XML DB also provides an implementation of the majority of the operators that will be incorporated into the forthcoming SQL/XML standard. proprietary APIs. allowing them to use the most appropriate tools to solving a particular business problem. By delivering on the promise of XML SQL duality. These tables are accessed and searched using the relational model and the power and openness of SQL from a variety of tools and processing engines. information contained in an Excel spreadsheet is only accessible to the Excel program. such as HTML using the database-resident XSLT processor. Oracle XML DB makes it possible to access XML content using SQL queries. Structured data on the other hand does not suffer from these limitations. With Oracle XML DB the relational and XML metaphors become interchangeable. Structured data is typically stored as rows in tables within a relational database. On-line Analytical Processing (OLAP) and Business-Intelligence/Data Warehousing operations. Organizations can easily leverage all of the information contained in their XML documents without having to incur the overhead of converting back and forth between different formats. or programmatically using complex. including SQL. Oracle XML DB provides new SQL operators that make it possible to generate XML directly from a SQL query. which is the main standards body for developing standards for the syntax and semantics of database languages. Page 23 of 116 January 31. stored in an XML document is accessible to any tool that can leverage the XML programming model.org/tc_home/h2. For instance. One of the major drivers behind the rapid adoption of XML is that it allows for stronger management and more open access to semi-structured and unstructured content.

The existsnode() operator is used in the where clause of a SQL statement to restrict the set of documents returned by a query. XPath is a popular syntax (see http://www. Each XPath expression identifies a target node in the document. and the ability to embed XPath expressions within SQL statements greatly simplifies XML access. Detailed examples of the way in which these functions are used are provided in the PurchaseOrder example. based on a set of XPath expressions. or an element which has precisely one text node child. The updatexml() operator allows multiple updates to be specified for a single XML document. The XPath expression passed to extractvalue() should identify a single attribute. If a single node matches the XPath expression the result will be a well-formed XML document. 2003 .org/TR/xpath) familiar to both programmer and contentcreators. and a new value for that node. The SQL/XML operators use XPath notation is used to traverse the XML structure and identify the node or nodes on which to operate. The updatexml()operator allows partial updates to be made to an XML document.w3. If multiple nodes match the XPath expression the result will be a document fragment. The result is returned in the appropriate SQL data type. The extract() operator takes an XPath expression and returns the node or nodes that matches the expression as an XML document or fragment. The operator and returns true (1) or false (0) depending on whether or not the document contains a node which matches the XPath expression. The existsnode() operator takes an XPath expression and expression and applies it an XML document. The extractvalue()operator takes an XPath expression and returns the corresponding leaf level node. The xmlsequence() operator makes it possible to expose the members of a collection as a virtual table. Page 24 of 116 January 31.Oracle XML DB Basic Demonstration The SQL/XML operators make it possible to address XML content in any part of a SQL Statement.

In this situation Oracle XML DB will create a DOM and then use the DOM to perform a functional evaluation of the XPath expressions. Functional evaluation builds a DOM tree for each XML document and then resolves the XPath programmatically using the methods provided by the DOM API. The database optimizer simply processes the re-written SQL statement in the same manner as it would any other SQL statement. The Query-rewrite process is as follows: • • • • In certain cases Query-rewrite is not possible. and this means that Query-rewrite allows Oracle XML DB to execute XPath based queries at near-relational speed while still preserving the XML abstraction. The SQL query references the Object-Relational data structures that underpin a schema-based XMLType. Page 25 of 116 January 31. The XMLType column or table uses structured storage techniques to provide the underlying storage model. allow XPath expressions to be used to search collections of XML documents and to access a subset of the nodes contained within an XML document. While this process is referred to as Query-rewrite. 2003 . Oracle XML DB will evaluate the XPath using functional evaluation. There is very little overhead associated with the process of Query-rewrite. This allows Oracle XML DB to leverage all of the features of the database and ensure that SQL Statements containing XPath expressions are executed in a highly performant and efficient manner. Identify the set of XPath expressions included in the SQL statement. it can also occur when performing update operations. Re-write the original SQL statement into an equivalent Object Relational SQL statement Pass the new SQL statement to the database optimizer for plan generation and query execution. Query-rewrite is possible in the following circumstances.Oracle XML DB Basic Demonstration XPATH AND QUERY RE-WRITE The SQL/XML operators. If the operation involves updating the DOM tree. the entire XML document has to be written back to disc when the operation is completed. For XML that has been stored using unstructured storage. to attributes of the underlying SQL object model. and the corresponding XMLType methods. This means that the database optimizer is able derive an execution plan based on conventional relational algebra. Oracle XML DB insulates the database optimizer from having to understand XPath notation and the XML data model. Oracle XML DB will attempt to translate the XPath expression in a SQL/XML operator into an equivalent SQL query. Translate each XPath expression into an Object Relational SQL expression that references the tables. Oracle XML DB has two methods of evaluating XPath expressions that operate on XMLType columns and tables. via the XML Schema. Query-rewrite makes it possible for the database to efficiently process SQL statements containing one or more XPath expressions using conventional relational SQL. • • • • The SQL statement contains SQL/XML operators or XMLType methods that use XPath expressions to refer to one or more nodes within a set of XML documents. This can occur when there is no SQL equivalent for a particular XPath expression. The nodes referenced by the XPath expression can be mapped. types and attributes of the underlying SQL: 1999 object model. The XMLType column or table containing the XML documents is associated with a registered XML Schema. For XML that has been stored using structured storage techniques. By translating the XPath expression into a conventional SQL statement.

updatexml() operators are used. extractvalue() . functional evaluation of a SQL statement will be much more expensive than Query-rewrite. However the advantage of functional evaluation is that it is can be used to evaluate any XPath expression.Oracle XML DB Basic Demonstration In general. When documents are stored using unstructured storage (in a CLOB). and the conditions under which query re-write can take place. is one of the key steps in developing Oracle XML DB applications that will deliver the required levels of scalability and performance Page 26 of 116 January 31. regardless of whether or not the XMLType is stored using structured storage and regardless of the expression’s complexity. particularly if the number of documents that needs to be processed is large. The existsNode() operator will also result in functional evaluation unless a CTXPATH index or functional index can be used to resolve the query. Understanding the concept of Query-re-write. functional evaluation will be necessary any time the extract() . 2003 .

The hierarchical index is totally transparent to the end-user. Oracle XML DB includes a new. The relational metaphor is not so effective when it comes to managing semi-structured and unstructured data. and to represent the hierarchy as a set of folders and subfolders. hierarchically organized XML Repository. such as paths and URLs. It is more natural to represent a book as a hierarchy. Using the repository. The WebDAV protocol is an IETF standard that defines a set of extensions to HTTP that allow an HTTP Server to act as a file server for a DAV enabled client. Page 27 of 116 January 31. Fig III. Since the HTTP.or content-orientated XML. This makes it possible to develop applications which access and update content managed by the Oracle XML DB repository. Oracle XML DB adds native support for these popular protocols to the database. and allows Oracle XML DB to perform folder and path traversals at speeds that are comparable to or faster than conventional file-systems. with its powerful table-row-column metaphor. such as document.Oracle XML DB Basic Demonstration XML DB REPOSITORY The relational model. A book does not easily lend it self to being represented as a set of rows in a table. book – chapter – section – paragraph. 2003 . Macromedia™ and Adobe™ to work directly with XML content stored in the Oracle XML DB repository. to access documents and represent the relationships between documents. Relational databases are traditionally considered to be poor at managing hierarchical structures and performing the kind hierarchical traversal operations that are required to resolve a path.and path-traversals with-in the Oracle XML DB Repository. In order to resolve this problem. The WebDAV standard uses the term resource to describe a file or a folder. Microsoft Office™ and products from vendors like Altova™. The majority of the tools used to author XML are now able to access content using internet protocols like HTPP. FTP and WebDAV. Oracle XML DB introduces the concept of a query-able. This terminology is adopted by the Oracle XML DB repository. is widely accepted as the most effective mechanism for managing structured data. allowing authors and editors direct access to content managed by the Oracle XML DB repository. Every resource managed by a WebDAV server is identified by a URL. patented hierarchical index which speeds up folder. The following screen shot shows the root level directory of the Oracle XML DB repository as seen from Microsoft’s Windows Explorer™. The Oracle XML DB repository allows the hierarchical metaphor to be used to manage document-centric XML content. and use hierarchical metaphors. By providing support for these protocols at the database level Oracle XML DB allows Windows Explorer™. Oracle XML DB also provides the application programmer with direct access to the repository from both SQL and PL/SQL. FTP and WebDAV protocols were designed with document-centric operations in mind. it is possible to represent XML content as documents in a folder hierarchy. Microsoft Web Folder™s view of Oracle XML DB repository. One of the major advantages of the Oracle XML DB repository is that it allows content authors and editors to work directly with XML content stored in the database. they are typically more efficient than Oracle NET for manipulating large volumes of content.

An Access Control List (ACL) is an XML document that contains a set of Access Control Entries (ACE). The XDB$RESOURCE table is not directly exposed to the SQL programmer. This user is created as part of the Oracle XML DB installation procedure. Operations on these views translate into operations on the underlying tables in the Oracle XML DB repository. The table contains one row for each file or folder managed by the Oracle XML DB repository. to set and change the access permissions on a file or folder and the ability to initiate and manage versioning. Oracle XML DB includes two new repository specific SQL operators: exists_path() and under_path() . any application capable of calling a PL/SQL procedure can work with the Oracle XML DB repository. the content of the document is stored in a LOB alongside the meta-data about the document Since the Oracle XML DB repository can be accessed and updated using SQL. The repository contains the meta-data about the document and a pointer (REF of XMLTYPE) that identifies the row in the default table that contains the content. The documents in this table are referred to as resource documents. All SQL and PL/SQL repository operations are transactional. It is possible to interrogate the structure of the repository in complex ways (“how many documents with a . This means that end users can work directly with the Oracle XML DB Repository using the tools and interfaces that they are already familiar with. 2003 . Content stored in the Oracle XML DB repository can be accessed and updated from SQL and PL/SQL. can connect directly to the XML DB repository. Both the RESOURCE_VIEW and the PATH_VIEW contain a column called RES.xsl extension are under a location other than /home/mystylesheetdir”?). It is also possible to mix path-based repository access with content-based access to the documents (“how many documents not under /home/purchaseOrders have a node named “/PurchaseOrder/User/text() with a value of “ DRAKE ”?) All the meta-data required to manage the Oracle XML DB repository is stored in a database schema owned by the database user XDB. The repository also provides support for basic versioning based on the WebDAV standard. delete and rename documents and folders. This is an XMLType column that can be used to access and update the resource asscociated with a document stored in the Oracle XML DB repository. Page 28 of 116 January 31. the RESOURCE_VIEW and the PATH_VIEW . It is also possible to store other kinds of documents in the repository. These operators make it possible to include path based predicates in the where clause of a SQL statement. The methods provided by these packages make it possible to create. and access to the repository and its contents is subject to database security as well as XML DB Repository Access Control Lists (ACLs). The RESOURCE_VIEW and PATH_VIEW provide the SQL programmer the ability to access and update both the meta-data and content of a document stored in the Oracle XML DB repository. Another benefit of the XML DB Repository is that it is query-able from SQL. to move a file or folder within the folder hierarchy. When non-xml and non-schema based XML documents are stored in the repository. No additional Oracle or Microsoft specific software or other complex middleware needs to be installed in order to enable this functionality. When Schema Based XML documents are stored in the Oracle XML DB repository the document content is stored as an object in the default table identified by the XML Schema. Each document in the Oracle XML DB is secured with an Access Control List. such as Microsoft’s Windows Explorer™. Instead the contents of the repository are exposed via two public views. The supplied PL/SQL packages DBMS_XDB . When repository content is accessed via SQL ACL based security is enforced via Row Level security. This means that SQL operations can select repository content based on the location of the content within the folder hierarchy. The Hierarchical Index ensures that path-based queries are executed very efficiently. This access control mechanism is based on the WebDAV specification. DBMS_XDBZ and DBMS_XDB_VERSION provide the SQL programmer the ability to perform common tasks on the repository itself. Each ACE grants or revokes a set of permissions to a particular user or group (database role). These views also make it possible to create SQL statements which access and update resource documents based on a path notation.Oracle XML DB Basic Demonstration As can be seen. WebDAV clients. The primary table in this schema is an XMLType table called XDB$RESOURCE.

All content. 2003 .Oracle XML DB Basic Demonstration The following diagram show the overall architecture of the Oracle XML DB repository SQL and non SQL clients access the repository using the Oracle Net Services Listener SQL clients access the repository via the PATH_VIEW and RESOURCE_VIEW or the DBMS_XDB PL/SQL package Non-SQL clients access content via the Oracle XML DB protocol servers. other than schema-based XML is stored in the repository.Oracle XML DB repository architecture overview Page 29 of 116 January 31. The Hierarchical Index enables high speed lookup based on a path SQL clients can access schema-based XML directly or via the repository Resource View and Path View DBMS_XDB PL/SQL Package HTTP. The content of Schema-based XML documents is stored in the default table defined by the Schema. The protocol servers are Oracle MTS processes All meta-data is managed by the Oracle XML DB repository. FTP and WebDAV Protocol SQL Client WebDAV or FTP Client HTTP Client Oracle Net Services Listener Servers Meta Data (DAV Resource) Hierarchical Index Non Schema-Based XML Content (LOB column) Non XML Content (LOB column) XML DB Repository Schema Based XML Content (XMLType Table or View) Fig IV.

) is treated as an atomic transaction. delete a file. The integration of the repository with the database brings the benefits of strong management to XML content. Using PL/SQL to update Oracle XML DB Repository Note that as a consequence of the transactional semantics enforced by the database. Once the operation has completed the change is immediately available to all other users of the file system. 2003 .Oracle XML DB Basic Demonstration The following screen shot shows the PL/SQL package DBMS_XDB being used to create a set of subfolders beneath the folder /home/SCOTT . In conventional file system there is no concept of a transaction. As the above example shows. create a subfolder. Page 30 of 116 January 31. In this situation a conventional locking strategy that takes an exclusive lock on each updated folder or directory tree would quickly result in significant concurrency problems and performance degradation. folders created using SQL statements will not be visible to other database users until the transaction is committed. one of the key advantages of the Oracle XML DB Repository is the ability to use SQL to perform repository operations in the context of a logical transaction. rename a file. One common problem encountered when using a relational database to maintain hierarchical folder structures is the problem of ensuring a high degree of concurrency when adding and removing items in a folder. Concurrent access to the Oracle XML DB repository is controlled by the same mechanism as is used to control concurrency in the database. This means that applications can create longrunning transactions that include updates to one or more folders. etc. Each operation (add a file. Fig V.

2003 . The Listener listens for HTTP and FTP requests in the same way that is listens for Oracle Net Services requests. moving or deleting a sub-folder or file do not require that the user performing the operation be granted an exclusive write lock on the target folder. WebDAV and FTP protocols are supported using the same architecture that is used to support Oracle Net Services in a Shared Server configuration. This concurrency problem is seen most commonly in situations where a number of applications are generating files quickly in the same directory. Repository operations such as creating. When the listener receives an HTTP or FTP request it hands it off to an Oracle Shared Server process which services it and sends the appropriate response back to the client. with FTP and HTTP protocol support enabled Page 31 of 116 January 31. the TNS Listener command lsnrctl status can be used to verify that HTTP and FTP support has been enabled. Only when the transaction is committed is the folder locked and the contents of the folder modified. The name and the modification type are put on a queue. Listener Status. THE ORACLE XML DB PROTOCOL A RCHITECTURE One of the key features of the Oracle XML DB architecture is that the HTTP. The Repository manages concurrent folder operations by locking the name within the folder rather than the folder itself. such as when generating trace or log files. This model allows Oracle XML DB to allow multiple applications to perform concurrent updates on the contents of a folder. The queue is also used to manage concurrency with the folder by preventing two applications from creating objects with the same name.Oracle XML DB Basic Demonstration XML DB solves this problem by providing for name-level locking rather than folder-level locking. As can be seen from the following screen short. or when maintaining a spool directory for printing or email delivery. Fig VI. Queuing folder modifications until commit time also has the side benefit of minimizing I/O when a number of changes are made to a single folder in the same transaction. renaming.

such as those based on XSLT transformations. need to have some ad vance knowledge of the structure of the data they are going to process. PL/SQL and Java. Programming to a DOM API is more flexible than programming via JDBC. servlets and JSPs access data via JDBC. Today. Java and PL/SQL implementations of the DOM API are provided. The Oracle JDBC drivers allow application programmers to access and update XMLType tables and columns. the most popular methods for building web-based applications are servlets/JSPs (Java Server Pages) and XSL/XSPs (XML Style sheets / XML Server Pages). Typically. but it may require more resources at run time. and to call the PL/SQL procedures that access the Oracle XML DB repository. Applications that make use of DOM. A DOM based application uses string names to identify pieces of content. while XSL/XSPs expect data in the form of XML documents. such as those based on servlets. Page 32 of 116 January 31. Applications that make use of JDBC. A ‘C’ implementation is forthcoming. Oracle XML DB supports both styles of application development. typically require less knowledge of the data structure. Oracle XML DB allows application developers to use the DOM API to access and update XMLType columns and tables. and must dynamically walk through the DOM tree to find the required information. 2003 . which are processed via a DOM (Document Object Model) API implementation.Oracle XML DB Basic Demonstration PROGRAMMATIC ACCESS All of the Oracle XML DB functionality is accessible from ‘C’.

in terms of memory. If an application only needs to process a small percentage of the nodes in the document this is extremely inefficient in terms of both memory and processing overhead. Oracle XML DB reduces the memory overhead associated with the DOM programming model by managing schemabased XML documents using an internal in-memory structure called a XML Object (XOB). The XOB can only used in conjunction with a XML document that is based on an XML Schema. A conventional DOM implementation requires that the entire contents of an XML document be loaded into the DOM tree before any operations can take place. The alternative SAX approach reduces the amount of memory required to process an XML document. and the number of collections in the document. data-centric XML. For highly-structured. Consequently. if an application only operates on few nodes in a document. Oracle XML DB uses the information contained in the associated XML Schema to dynamically reconstruct any necessary tag information. only those nodes and their immediate siblings will be loaded into memory. Oracle XML DB incorporates a number of features that are specifically designed to address this issue by significantly improving the performance of XML processing. The amount of space saved by this optimization depends on the ratio of tag names to data. or when node-based operations such as XPath evaluations take place. When a document is printed. 2003 . The XOB is also able to reduce the amount of memory required to work with an XML document via a feature called the Lazily-Loaded Virtual DOM. a traditional DOM will be used instead of the XOB. all of the data in an XML file is represented in human readable (string) format. There are two reasons for this. A XOB is much smaller than the equivalent DOM since it does not duplicate information like tag names and node types. which can easily be obtained from the associated XML Schema. XML STORAGE REQUIREMENTS Surveys have shown that data represented in XML and stored in a text file is three times the size of the same data in a Java object or in relational tables. In the case of numeric data the string representation of a numeric value needs about twice as many bytes as the native (binary) representation When XML documents are stored in Oracle XML DB using the structured storage option. The use of the XOB is transparent to the application developer.Oracle XML DB Basic Demonstration ORACLE XML DB PERFORMANCE One common objection to using XML to represent data is that it generates higher overhead than other representations. Oracle XML DB will automatically use a XOB whenever an application is working with the contents of a schema-based XMLType. XML MEMORY MANAGEMENT The Document Object Model (DOM) is the dominant programming model for XML documents. This feature allows Oracle XML DB to defer loading the in-memory representation of nodes that are part of sub-elements or collection until some methods attempt to operate on a node within that object. the ‘shredding’ process discards all of the tags and white space contained in the document. Secondly. This means that for highly structured data the DOM tree can require 10-20 times more memory than the document on which it is based. but has the major disadvantage that it only allows linear processing of the nodes contained in the XML Document. it is hidden behind the XMLType data-type and the ‘C”. The DOM APIs are very easy to use but the DOM Tree that underpins them is expensive to generate. PL/SQL and Java APIs. Page 33 of 116 January 31. data-centric XML the savings can be significant. First. tag names (metadata describing the data) and white space (formatting characters) take up a significant amount of space in the document. If the contents of the XML document are not based on an XML Schema. A typical DOM implementation maintains approx 80 – 120 bytes of system overhead for each node in the DOM tree.. particularly for highly structured.

Oracle XML DB is able to write just the updated data back to disk. The means that performing even a simple search of a DOM tree can require hundreds or thousands of instruction cycles. For instance. Once again. Oracle XML DB eliminates the need to keep re-parsing documents. XML SCHEMA OPTIMIZATIONS Making use of the powerful features associated with XML Schema in a conventional XML application typically generates significant amounts of additional overhead. Oracle XML DB allows these operations to be off-loaded to the client or mid tier processor. or serializing an XML document back into text form can still require significant memory and CPU resources. The cached representation of the XML Schema can also be downloaded to the client. In a typical DOM based application. The schema cache is shared by all users of the database. Whenever an Oracle XML DB operation requires information contained in the XML Schema it is able access the required information directly from the cache. LOAD BALANCING Some operations. rather than server resources. and XML Schema validation to performed using client or mid-tier resources. XOB and on-disk representations of the data. When changes are made to the contents of a schema-based XMLType. every document has to be parsed and loaded into the DOM tree before the application can work with it. parsed and validated. The OCI interface and thick JDBC driver both allow the XOB to be managed by the client. Once an XML document has been stored using structured storage techniques no further parsing is required when the document is loaded from disk into memory. along with all of the meta-data required to map between the XML. This allows operations like XML printing. Oracle XML DB minimizes the overhead associated with using XML Schema. When an XML Schema is registered with the database it is loaded in the Oracle XML DB Schema cache. This means that once the XML Schema has been registered with the database no additional parsing or validation of the XML Schema is required before it can be used.intensive. 2003 . such as performing a full Schema validation. Oracle XML DB is able to map directly between the on-disk format and in-memory format using information derived from the associated XML Schema.Oracle XML DB Basic Demonstration XML PARSING OPTIMIZATIONS In order to populate a DOM tree the application must parse the XML document. Page 34 of 116 January 31. A XOB is based a computed offset model (similar to a C/C++ object) and it uses dynamic hash-tables rather than string comparisons to perform node searches. Searching for a node in a XOB is much more efficient than searching for a node in a DOM. The process of creating a DOM tree from an XML file is very CPU. the schema itself must be located. NODE SEARCHING OPTIMIZATIONS Most DOM implementations suffer from the fact that they use string comparisons when searching for a particular node within the DOM tree. when the contents of the XMLType are not based on an XML Schema a traditional DOM will be used instead. where the XML documents are stored as text. If the contents of the DOM tree are updated the whole tree has to be serialized back into a text format and written out to disk. before an XML document can be validated against an XML Schema.

Avoiding unnecessary type conversions can result in significant performance improvements in the cases where an application only needs to access a few of the nodes contained in an XML document. This provides for language-neutral XML support (Java. Typical JSP implementations would read the name from the database (which probably contains data in the ASCII or ISO8859 character sets) convert the data to UCS-2. One of the major performance bottlenecks in implementing XML applications is the cost of transforming the data contained in an XML document between text. PL/SQL and SQL are all using the same underlying implementation).Oracle XML DB Basic Demonstration NON-NATIVE CODE Another bottleneck for XML-based Java applications is the cost associated with parsing an XML file. Data remains in the internal representation until the last possible moment. Consider the case of a JSP that wants to load a name from the database and print it out in the generated HTML output. Lazy type conversions mean that the contents of a given node will be not be converted into the format required by Java until the application attempts to access the contents of the node. but merely print it out after printing the enclosing HTML. XML DB provides a write interface on XMLTYPE so that any element can write itself directly to a stream (such as a ServletOutputStream) without conversion through Java character sets. ‘C’. Most XML files and databases do not contain UCS-2 encoded data. as well as for high performance XMP parsing and DOM processing. XML DB addresses these problems with lazy type conversions. Internally Java uses UCS-2 to represent all character data. TYPE CONVERSIONS One of the biggest bottlenecks in using Java in conjunction with XML is the cost of type conversions. Page 35 of 116 January 31. 2003 . Java and the native server representations. The cost of performing these transformations is proportional to the size and complexity of the XML file and becomes quite severe with even moderately sized files. probably converting back to the same ASCII or ISO8859 for the client browser. and return it to Java as a String. The JSP wouldn't look at the contents of the string. Oracle XML DB addresses these issues by implementing all of the Java and PL/SQL interfaces as very thin facades over a native ‘C’ implementation. Even natively compiled or JIT compiled Java performs XML passing operations twice as slowly as native ‘C’ implementations. This means that all the data contained in an XML file has to be converted from 8 Bit or UTF8 encoding into UCS-2 encoding before it can be manipulated inside a Java program.

with Oracle XML DB there is no need to compromise on the enterprise-class database features in order to get native XML support. providing all of the reliability. scalability and unbreakable security features needed to run mission-critical applications. Page 36 of 116 January 31. Oracle XML DB Application Programming Stack XML MANAGEABILITY Unlike niche ‘native XML’ database. high availability.Oracle XML DB Basic Demonstration OCI-Based Application ‘C’ XMLType and DOM JAVA XMLType and DOM JAVA XMLType and DOM Server-Based Application PL/SQL XMLType and DOM Schema-Based XML (XOB) In Memory Format Non-Schemabased XML (DOM) XML Schema Cache Structured Storage (Objects) Unstructured Storage (CLOB) On Disk Format Fig VII. The rest of this white paper will take a detailed look at the above features in terms of a simple example of using Oracle XML DB to manage XML documents. Oracle XML DB is not a separate server. 2003 . it is an integral part of the Oracle database.

Demonstration Folder. the Icons in this folder are numbered. Fig VII. showing ICONS used to run the Oracle XML DB basic demo As you can see. When you open the folder you will see the following Icons. 2003 . The demonstration is given by clicking on each of the Icons in this folder in turn Page 37 of 116 January 31. open the folder “XML DB Basic Demo”.Oracle XML DB Basic Demonstration PERFORMING THE DEMONSTRATION To start the demonstration. If the demo has been installed correctly this folder will be located on your Desktop.xml. Note that you can override the default name of this folder by specified in installParameters.

and ensures that all necessary permission have been granted to the target user. The script creates some global database objects that are used elsewhere in the demonstration. set the appropriate ACL on the folder.Oracle XML DB Basic Demonstration 0.1 INITIAL SETUP (RUN ONCE ) Before giving the demonstration for the first time it is necessary to run this script. This script does not need to be run again unless the database is dropped and re-created. This script will remove all files under the chosen user’s home folder and ensure that the environment is clean.2 RESET DEMO Prior to giving the demonstration it is necessary to run this script. Page 38 of 116 January 31. 2003 . 0. creates the ‘/home’ folder.

0 XML DB REPOSITORY This step demonstrates how the WebDAV protocol makes it possible to access the XML DB repository using the using Windows Explorer.Oracle XML DB Basic Demonstration 1. adaptors or drivers need to be installed in order for these tools to work with the Oracle XML DB repository. The following window should be displayed: Fig VIII.. This will establish a WebDAV connection to the XML DB repository. Since the repository supports the HTTP. Page 39 of 116 January 31. Enter the appropriate database user and password and click OK. 2003 . This folder will contain a folder named for demonstration user. In this example the demonstration is being run using the database user SCOTT so the folder is called SCOTT . WebDAV and FTP protocols. No plug-ins.0 XML DB Repository ”. You will be prompted for username and password. and other kinds of content. Double-click on the demonstration users’ home folder. it is possible to access content stored in the XML DB repository using standard tools like Windows Explorer and Microsoft Office. Microsoft Web Folders view of Oracle XML DB repository Double-click on the home folder icon. Click once on the shortcut “1. This will launch Window Explorer and open a folder containing a shortcut called “XML DB on hostname”. The Oracle XML DB repository allows a file / folder metaphor to be used to organize and manage XML. Click on this shortcut .

Using Windows Explorer to create a folder in the Oracle XML DB repository Give the new folder a clearly identifiable name. Create a new folder by clicking the right mouse button and selecting New -> Folder. with the name specified.Oracle XML DB Basic Demonstration This will display an empty folder. Fig IX. Fig X. 2003 . The home folder should now contain one sub-folder. Home Folder with newly created sub-folder Page 40 of 116 January 31.

The WebDAV standard uses the term resource to describe a file or a folder. Adobe and Macromedia. WebDAV is an IETF standard that defines a set of extensions to the HTTP protocol that allow an HTTP Server to act as a file server for a DAV enabled client. 2003 .Oracle XML DB Basic Demonstration KEY POINTS : • Windows Explorer can connect directly to the XDB repository. This means that end users can work with the Oracle XML DB repository using the tools and interfaces that they are already familiar with. Acrobat and Dreamweaver are able to work directly with content stored and managed by Oracle XML DB. in this case the WebDAV protocol. This means that applications such as Word. Many vendors. This connectivity is possible because Windows Explorer and Oracle XML DB both support open. Page 41 of 116 January 31. Every resource managed by a WebDAV server is identified by a URL. are including support for WebDAV in their product sets. Excel. internet standards. • • • Do not close the WebDAV window at this point. No additional Oracle or Microsoft specific software has to be installed in order to make this work. including Microsoft.

Fig XI. It also shows that. 2003 . This means that any program that can call a PL/SQL procedure can work with the Oracle XML DB repository.1 MAKE DIRECTORIES This step demonstrates that the Oracle XML DB repository can be accessed and updated from SQL. as well as via the protocols. Execute the SQL script by clicking on the Icon. Using PL/SQL to update Oracle XML DB Repository The script will result in a set of folders being created inside the folder /home/SCOTT. Page 42 of 116 January 31. KEY POINTS : • • The Oracle XML DB repository SQL to be used to access and manipulate repository and well as standard protocols such as WebDAV and FTP. Do not continue the SQL*PLUSW session at this point.Oracle XML DB Basic Demonstration 1. when accessed via SQL. repository operations are transactional. The PL/SQL package DBMS_XDB can be used to perform operations on the repository from SQL.

even after refreshing the display. 2003 . Fig XII. Note that the folders that were created by executing the PL/SQL script are NOT visible. PL/SQL operations are transactional. and the transaction has not been committed.Oracle XML DB Basic Demonstration Click on the window containing the WebDAV view of the demonstration user’s home folder. Page 43 of 116 January 31. Consequently the changes made in the PL/SQL session are not visible to other users. Windows Explorer unable to see uncommitted changes to Oracle XML DB repository KEY POINTS : • This is the expected behavior. Refresh the contents of this Window.

2003 . Fig XIII. Close the WebDAV window. Fig XIV. Committing changes to the Oracle XML DB Repository The script will issue a COMMIT statement. Windows Explorer able to see changes to Oracle XML DB repository after commit Press any key to complete the SQL*PLUS session. Refresh the contents of this Window. Note that the folders that were created by executing the PL/SQL script are now visible after refreshing the display. Page 44 of 116 January 31.Oracle XML DB Basic Demonstration Click on the Window containing the SQL*PLUS session and press any key to continue execution of the SQL Script. Click on the window containing the WebDAV view of the demonstration user’s home folder.

You can see from the output of the status command that the listener is service Oracle Net Services requests on 1521. with FTP and HTTP protocol support enabled KEY POINTS : • • The listener’s status command can be used to verify that HTTP and FTP support have been enabled. The Listener listens for HTTP and FTP requests in the same way that is listens for Oracle Net Services requests.xml. Click once on this icon to display the status of the TNS Listener using the command lsnrctl status. When the listener receives an HTTP or FTP request it hands it off to an Oracle Shared Server process which services it and sends the appropriate response back to the client. Note if a remote server is being used to host the database then the command will need to be executed on the remote machine. Fig XV. When the listener receives an HTTP or FTP request it hands it off to an Oracle Shared Server process which services it and sends the appropriate response back to the client. xdbconfig. HTTP requests on 8080. 2003 . Listener Status. One of the key features of the Oracle XML DB architecture is that the HTTP.2 ORACLE XML DB PROTOCOL ARCHITECTURE This step demonstrates that the protocol support is provided using the standard Oracle Listener and shared server architecture. The Listener listens for HTTP and FTP request in the same way that is listens for Oracle Net Services requests. • • • Page 45 of 116 January 31. WebDAV and FTP protocols are supported using the same architecture that is used to support Oracle Net Services in a Shared Server configuration. One of the key features of the Oracle XML DB architecture is that the HTTP.Oracle XML DB Basic Demonstration 1. The port numbers can be configured using OEM or by editing the Oracle XML DB configuration file. WebDAV and FTP protocols are supported using the same architecture that is used to support Oracle Net Services in a Shared Server configuration. This file is found in the root of the Oracle XML DB repository. and FTP requests on 2100. The following window should be displayed.

Using Windows Explorer ™ to load content into the Oracle XML DB Repository KEY POINTS : • • • Windows Explorer™ and the WebDAV protocol can be used to upload documents into the XML DB repository. The second is a Windows shortcut that points to the target folder in the Oracle XML DB repository. Examples of this include registering an XML Schema and performing an XSL transformation. Authenticate as necessary. 2003 . The Oracle XML DB repository can be used to store non XML content. Drag the local folder onto the shortcut to the Oracle XML DB repository. as well as Schema based and non-Schema based XML content. Close the WebDAV Folder. JPEG images. such as HTML files. Click once on this icon to open the configurationFiles folder. The easiest way to make the necessary documents available to Oracle is to load them into the Oracle XML DB repository. This will copy the files from the local folder into the Oracle XML DB repository Fig XVI. The first is a local folder containing the configuration documents that need to be loaded into the repository. This folder contains two items.3 LOAD CONFIGURATION FILES This step show how Windows Explorer can be used to load Oracle XML DB configuration documents into the Oracle XML DB repository. Many of the operations associated with configuring and using Oracle XML DB are based on processing one or more XML documents.Oracle XML DB Basic Demonstration 1. an HTML page and a couple of XSLT style sheets. Page 46 of 116 January 31. This procedure uploaded the poSource directory tree to the Oracle XML DB repository. word documents etc. The following screen shot shows a simple drag and drop operation being used to copy the contents of the poSource folder from the local hard drive into the Oracle XML DB Repository. This directory tree contains an XML Schema document. WebDAV support makes it possible to load these documents from a local file system into the Oracle XML DB repository using Windows Explorer™.

SPP 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 SQL 99 object types.Oracle XML DB Basic Demonstration 2.xsd. Click once on the icon to launch the XMLSpy Integrated Development Environment.altova. CREATING AND EDITING AN XML SCHEMA The first section shows how XMLSpy can be used to create and edit a simple XML. Enter the database username password and Click OK XML Spy will open the XML Schema and display a list of the elements and types defined by the XML Schema. You will be prompted for a user name and password. XMLSpy is a XML Schema and document editing tool created by Altova. interface for creating and editing an XML Schema. Click on the + sign next to the DTD/Schemas entry in the Project Pane tree. One of the major features of the XMLSpy IDE is that it provides a developer with a graphical. This allows XMLSpy to directly access content stored in Oracle XML DB Repository. accessible via the following URL: http://localhost:8080/home/SCOTT/poSourcexsd/purchaseOrder. 2003 . See http://www. This branch will contain a single XML Schema. Fig XVII.com for more details about the tool and its features. XMLSpy also supports both WebDAV and FTP protocols. easy to use.0 SHOW XML SCHEMA. Double-click this item to open it. XMLSpy showing Elements and Type view of an XML Schema Page 47 of 116 January 31.

XML Schema allows for strong typing of the elements and attributes in a document. It defines 47 scalar data types.Oracle XML DB Basic Demonstration KEY POINTS • • Oracle XML DB supports the W3C XML Schema standard. An XML Schema is itself an XML document which is compliant with a well known XML Schema defined by the W3C. easy to use interface for creating and editing XML Schemas. • • • • Page 48 of 116 January 31. known as the Schema for Schemas. The base set of types defined by XML Schema can be extended using object orientated techniques like inheritance and extension to define more complex types. 2003 . The XML Schema standard defines an XML language that can be used to define the structure of a set of XML documents. Oracle XML DB can use XML Schema in this manner. XMLSpy provides developers with a graphical. XMLSpy supports both WebDAV and FTP protocols. The most common usage of an XML Schema is as a mechanism for validating that a set of instance documents are conformant with the XML Schema. This allows XMLSpy to directly access content stored in Oracle XML DB.

The global element PurchaseOrder is an instance of the complexType PurchaseOrderType. The PurchaseOrder schema is a relatively simple XML Schema that demonstrates the key features of a typical XML document. Page 49 of 116 January 31. and Part. followed by the + sign next to the LineItem element. Finally click on the Part element. Quantity and UnitPrice . This will show a graphical representation of the structure of the PurchaseOrder element.Oracle XML DB Basic Demonstration Click on the control next to the PurchaseOrder element. Click on the + sign next to the LineItems element. XMLSpy showing a Graphical Representation of an XML Schema KEY POINTS : • • XMLSpy proves a XML Schema editor with an easy-to-understand. 2003 . PurchaseOrderType defines • • • • • the set of nodes which make up a PurchaseOrder element. Description The LineItems element consists of a collection of LineItem elements. The Part element has attributes Id. Fig XVIII. Each LineItem elements consists of two elements. graphical representation of an XML Schema.

com/xdb is the namespace reserved by Oracle for the Oracle XML DB schema annotations.Oracle XML DB Basic Demonstration Click on the control on the Toolbar. This namespace is used to add annotations to the schema that control how the instance documents will be stored in the database. This schema defines two namespaces. 2003 . is the namespace reserved by the W3C for the Schema for Schemas. The first.oracle. This will switch the XMLSpy editor into text mode and display the XML Schema as an XML document. • The annotation mechanism is the W3C approved mechanism for adding vendor specific information to a W3C XML Schema. http://www. Fig XIX. This namespace is used to define the structure of the XML document. which is an XML document compliant with the W3C XML Schema Working Group’s “Schema for Schemas ”. http://xmlns.w3c. Page 50 of 116 January 31.org/2001/XMLSchema. The second. XMLSpy showing the native Representation of an XML Schema KEY POINTS : • • XMLSpy also allows the XML Schema editor to work directly with the XML Schema in its native form.

storing the entire collection as a VARRAY of objects stored in a LOB column.Oracle XML DB Basic Demonstration A NNOTATING AN XML SCHEMA Database administrators and Application developers can annotate the XML Schema to control the naming of the Tables. These options provide significant opportunities to tune the performance of applications that make use of the XMLType data-type to store XML in the database. 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 from the complexType PurchaseOrderType. SQL Objects and SQL Attributes created during the Schema registration process. Annotations can be used to override the Oracle XML DB defaults for the following items: The names of the Tables. storing the collection as a set of rows in an Index Organized Nested Table. or storing the collection as a set of rows in a separate XMLType table. In this schema the following annotations are being used: The storeVarrayAsTable annotation is used to force collections to be stored as Nested Tables. It makes use of a set of default assumptions to register the XML Schema. Annotations also make it possible to control how collections with the XML Schema are stored in the database. The available options include storing the collection as CLOB. • Controlling how collections are managed gives database administrators and Application developers the ability to tune the data mode to meet the requirements of the application. • Oracle XML DB can register an XML Schema which contains no annotations. 2003 . How collections are stored. • Page 51 of 116 January 31. The annotations provide the application developer or database administrator with the ability to override these assumptions. The annotations provide the application developer or database administrator with the ability to override these assumptions. Annotations can also override the default mapping between the XML Schema data types and SQL data types. The defaultTable annotation is used in the PurchaseOrder element to define that XML documents. The mapping of XML Schema data-types to SQL data-types. SQL Objects and SQL Attributes derived from the XML Schema. It makes use of a set of default assumptions to register the XML Schema. KEY POINTS : • Oracle XML DB can register an XML Schema which contains no annotations.

icon next to the PurchaseOrderType complexType. Click on the This will display a graphical representation of the complexType PurchaseOrderType. 2003 . Do not close this window yet. Fig XX. This will show the Oracle XML DB tab. Page 52 of 116 January 31. XMLSpy showing support for Oracle XML DB Schema Annotations KEY POINTS • This tab allows an XML Schema author to enter Oracle XML DB Schema annotations while working in the XMLSpy graphical editor. Click on the Oracle Tab in Details dialog box.Oracle XML DB Basic Demonstration Click on the control on the Toolbar This will switch the XMLSpy editor back in graphical mode.

The registerSchema() procedure is responsible for creating all of the objects and type defined by the XML Schema. By default. The URL is the URL that an instance document will use when identifying itself as a member of the class defined by the XML Schema.1 REGISTER SCHEMA The step demonstrates the process of registering an XML Schema stored in the Oracle XML DB repository. The database is not aware of the existence of the XML Schema. • • Press any key to complete the SQL*PLUS session. Using the DBMS_XMLSCHEMA package to register an XML Schema KEY POINTS : • The Schema is registered under a URL. Page 53 of 116 January 31.registerschema(). The URL is simply a key used to associate the instance document with the registered Schema. XML Schema registration is performed using a simple PL/SQL procedure: called dbms_xmlschema. 2003 . Oracle XML DB does need to be able to access the target of the URL. when the XML Schema is registered. Before Oracle XML DB can manage the instance documents associated with a given XML Schema the XML Schema must be registered with the database. Oracle XML DB will automatically generate all of the SQL Object Types and Object tables required to manage the instance documents. This method of 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.Oracle XML DB Basic Demonstration 2. At this point in the demonstration the XML Schema has simply been stored in the Oracle XML DB repository. Fig XXI. Execute the SQL script by clicking on the Icon.

Page 54 of 116 January 31. This will be the default table for this XML Schema. Execute the SQL script by clicking on the Icon. Fig I. A table called PURCHASEORDER .2 SHOW OBJECTS This step describes some of the objects that were created as a result of registering the XML Schema.Oracle XML DB Basic Demonstration 2. Tables and Objects created as a result of XML Schema registration KEY POINTS : • The following objects were created a result of registering the Schema. 2003 . There will be one row in the table for each PurchaseOrder document loaded into the Oracle XML DB Repository. By default the XML Schema registration process generates the SQL Objects and XMLType tables required to manage the instance documents.

the tables created are given system generated names.Oracle XML DB Basic Demonstration The PURCHASEORDER table is an Object table. Currently. Press any key to complete the SQL*PLUS session. Close XMLSpy. XDBPO_LINEITEMS_TYPE consists of a single attribute LINEITEM. Compare the SQL*PLUS description of the XDBPO_TYPE with the graphical representation of the complexType PurchaseOrderType. Fig XXII. When an instance document is stored in the PURCHASEORDER table it will be shredded and stored as instance of the XDBPO_TYPE.xsd contains the definition of PurchaseOrder element. 2003 . The table manages XML documents with a root node of PurchaseOrder. This means each element in the VARRAY will be stored as a separate row in a Nested Table. XDBPO_LINEITEM_COLLECTION contains a VARRAY of XDBPO_LINTEITEM_TYPE objects. Each row in the table is represented by a SQL object. Renaming Nested Tables Click the XMLSpy window. There will be one instance of the XDBPO_LINEITEM_TYPE object for each LineItem element in the document. Note that each element or attribute in the complexType has a corresponding SQL Attribute in the definition of XDBPO_TYPE. when this annotation is used to create Nested Tables. These types are used to manage the collection of LineItem elements that can occur within a PurchaseOrder document. which is defined as being an instance of the XDBPO_LINEITEMS_COLLECTION type. The object in question is an XMLType. This SQLType will be used as the underlying storage model for the XMLType objects in the PURCHASEORDER table. SQL Types called XDBPO_LINEITEMS_TYPE. Page 55 of 116 January 31. The XML Schema http://localhost:8080/home/SCOTT/poSource/xdb/purchaseOrder. A SQL Type called XDBPO_TYPE. • The Oracle XML DB XML Schema annotation storeVarrayAsTable =”true” was included in the root element of the PurchaseOrder XML Schema. The definition of the type was derived from the complexType PurchaseOrderType. XDBPO_LINEITEMS_COLLECTION and XDBPO_LINEITEM_TYPE. Press any key to continue execution of the SQL Script.

Right click on the document BLAKE-2002100912333601PDT. 2003 .Oracle XML DB Basic Demonstration 3.xml and select Open. The noNamespaceSchemaLocation attribute is used to identify the document as an instance of the class of documents defined by the XML Schema. Double-click on the 2002 folder. This will launch Internet Explorer and display the document shown below . Click once on this icon to open the sampleData folder. WebDAV and the Oracle XML DB repository to load content directly into an XMLType table. Double-click on the Mar folder. Close the browser. The second step demonstrates how to use Windows Explorer . If the document opens with some other application use the Folder Options feature of Windows Explorer to adjust the file association. The first step demonstrates that the XML files being loaded are correctly identified as being instances of the class defined by the PurchaseOrder XML Schema. A XML Document with noNamespaceSchemaLocation tag KEY POINTS : • • The file is compliant with the XML Schema. Page 56 of 116 January 31. Fig XXIII.0 LOAD SAMPLE DATA This step demonstrates how to load XML files into the Oracle XML DB.

Oracle XML DB

Basic Demonstration

There are several ways of storing XML in an XMLType. • From SQL or PL/SQL a simple insert statement can be used to load data. The data can come from a variety of sources. Before the data can be stored as an XMLType is must first be converted from the source form into an XMLType instance using one of the XMLType constructors. There are a number of variants of the XMLType constructor which allow an XMLType to be created from a number of different sources including VARCHAR and CLOB data types. The constructors also provide options for reducing the amount of processing associated with creating the XMLType. For instance, if the source XML Document is known to be both Well formed and Valid, the constructor allows flags to be passed that disable the default checking that is typically performed when instantiating the XMLType. It is also possible to use the Oracle XML DB repository to store XML in an XMLType table. The XML in question must be schema based, and it will be stored in the Default Table associated with the XML Schema. For the SQL programmer the PL/SQL package DBMS_XDB provides methods which can be used to load an XML Document into the Oracle XML DB repository. XML documents can also be loaded into the repository using the FTP, HTTP and WebDAV protocols. When a schema-based XML document is loaded into the Oracle XML DB repository Oracle XML DB will automatically recognize the document, shred it and store it in the Default Table defined by the XML Schema.

Navigate back to the sampleData folder. Select the 2002 folder and drag it onto the shortcut that points to the purchaseOrders folder in the Oracle XML DB repository.

Fig XXIV. Request for authentication when accessing Oracle XML DB Repository via WebDAV

Authenticate as necessary. This will copy the 2002 folder and all of its contents from the local hard drive into the Oracle XML DB repository..
purchaseOrders folder

in the

Page 57 of 116

January 31, 2003

Oracle XML DB

Basic Demonstration

Fig XXV. File Copy Operation in progress

KEY POINTS :
• Windows Explorer load ed content directly into the Oracle Database. No additional moving parts or servers were required. This is possible because Oracle XML DB adds support for FTP and HTTP and WebDAV to the set of protocols understood by the database. Since the root node of each document included a noNamespaceSchemaLocation attribute that identified them as an instance of the PurchaseOrder XML Schema, the documents were shredded and stored as a set of objects in the PURCHASEORDER table.

Close the sampleData window. Open the main demonstration folder, located on the Windows Desktop.

Page 58 of 116

January 31, 2003

Oracle XML DB

Basic Demonstration

3.1 ADD CONSTRAINTS
This step demonstrates that it possible to leverage SQL functionality when storing XML documents in Oracle XML DB. It shows adding relational constraints to the table that contains the XML Data, and how to enable full schema validation of the XML documents. XML Schema is a very powerful language. However there are some simple data management concepts that are not addressed in the current version of the XML Schema standard. These include the ability to define that the value of an element or attribute has to be unique across of a set of XML documents (a UNIQUE constraint), or that the value of an element or attribute must exist in some data source outside of the current document (a FOREIGN KEY constraint). Oracle XML DB allows database enforced integrity to be applied to XML content. The mechanisms used to enforce integrity on XML are the same as the mechanisms that are used to enforce integrity on conventional relational data. Simple rules, like uniqueness and foreign key relationships are enforced by using constraints. More complex rules are enforced using database triggers. The following screen shot shows how constraints and triggers can be used to enforce a set of business rules associated with the PurchaseOrder documents.

Fig XXVI. Applying Database Integrity Constraints and Triggers to an XMLType table.

Page 59 of 116

January 31, 2003

Oracle XML DB Basic Demonstration KEY POINTS : • • • The unique constraint RERENCE_IS_UNIQUE will enforce the rule that the value of the node /PurchaseOrder/Reference/text() is unique across all documents stored in the PURCHASEORDER table The foreign key constraint USER_IS_VALID will enforce the rule that the value of the node /PurchaseOrder/User/text() corresponds to one of the values in the ENAME column in the EMP table. when referring to the content of an XMLType table from within a trigger it is necessary to refer to the object being inserted. Performing a full XML Schema validation is a fairly expensive process. If the developer is not sure about the validity of the XML. If the developer is sure that the XML is always valid. they can avoid overhead of performing a full validation on the incoming XML document. a simple trigger is all that is required to enforce a full validation. In order to enforce a full schema validation the schemaValidate() method has to be called on the XMLType. 2003 . By default Oracle XML DB performs a simple ‘lax’ validation of the incoming XML Document which ensures that mandatory information is present and that there are no unexpected elements or attributes in the document. • In the current release of Oracle XML DB it is necessary to define a constraint in terms of the derived SQL object model. updated or deleted using the name SYS_NC_ROWINFO$ . The trigger VALIDATE_PURCHASEORDER will enforce the rule that the PurchaseOrder document must be in full compliance with the associated XML Schema. Page 60 of 116 January 31. Also. This design allows the developer to determine if a full validation is required.

2003 . Page 61 of 116 January 31. the constraint REFERENCE_IS_UNIQUE is violated. Since the unique key constraint is violated the ftp ‘put’ operation fails. The XML document is valid according to the XML Schema. Violating a Unique Constraint via FTP KEY POINTS : • Since there already is a document in the database which contains a reference element with the same value. When the document is uploaded the follow ing error is displayed ORA-00604: error occurred at recursive SQL level 1 ORA-00001: unique constraint (SCOTT. The first example uses FTP to attempt to upload a document that violates the unique constraint that has been defined on the PURCHASEORDER table. or uploaded using a protocol. Launch FTP and upload the document by clicking on the icon.2 DUPLICATE REFERENCE The next 3 steps demonstrate that business rules defined using constraints and triggers are applied to XML content regardless of whether XML is inserted directly into a table. However the node /PurchaseOrder/Reference/text() contains a value which is a duplicate of one of the documents that has already been loaded into Oracle XML DB.REFERENCE_IS_UNIQUE) violated Fig I. Close the FTP session by type QUIT at the ftp> prompt.Oracle XML DB Basic Demonstration 3.

However the node /PurchaseOrder/User/text() contains the value “HACKER ”. Launch FTP and upload the document by clicking on the icon. The XML document is valid according to the XML Schema.2 INVALID USER This example uses FTP to attempt to upload a document that violates the foreign key constraint that has been defined on the PURCHASEORDER table. the constraint violated.USER_IS_VALID) violated .parent key not found Fig XXVII. When the document is uploaded the following error is displayed ORA-00604: error occurred at recursive SQL level 1 ORA-02291: integrity constraint (SCOTT. Since the foreign key constraint is violated the ftp ‘put’ operation fails.Oracle XML DB Basic Demonstration 3. 2003 . Violating a Foreign Key Constraint via FTP KEY POINTS : • Since the value “HACKER ” does not appear in the ENAME column of the EMP table. There is no row in the EMP table where the ENAME column contains the value “HACKER ”. USER_IS_VALID is Page 62 of 116 January 31.

Oracle XML DB

Basic Demonstration

3.3 INVALID DOCUMENT
This example uses FTP to attempt to upload a document that is not valid according to the associated XML Schema. The XML Schema defines a minimum length of 18 characters for the node /PurchaseOrder/Reference/text(). In this document the node contains the value “ADAMS-20011127PST”, which is only 15 characters long. Launch FTP and upload the document by clicking on the icon. 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'

Fig XXVIII. Violating a SchemaValidate constraint via FTP

Page 63 of 116

January 31, 2003

Oracle XML DB

Basic Demonstration

KEY POINTS :
• The full XML Schema validation performed by the VALIDATE_PURCHASEORDER trigger catches the fact that the document is not valid according to the XML Schema. Since the trigger returns an error, the ftp ‘put’ operation fails and the document is not uploaded. Without the trigger the document would pass the default ‘lax’ validation performed when a document is loaded into an XMLType table. When a document is being uploaded via a protocol, Oracle XML DB always provides the client with the full SQL Error Stack. How the error is interpreted and reported to the user is determined by the error handling built into the client application. Some clients will report the error returned by Oracle XML DB, while others will simply report a generic error message. Oracle XML DB will enforce business rules on XML Content. Constraints and triggers are enforced even when protocols are used to upload content into the database. By using the database to manage XML we get the power of SQL combined with flexibility of XML. Storing XML documents in Oracle XML DB allows organizations to can bring the Reliability, Availability, Scalability and Security of the Oracle database to bear on XML content.

• • • •

Close the FTP session by type QUIT at the ftp> prompt.

Page 64 of 116

January 31, 2003

Oracle XML DB

Basic Demonstration

4.0 SIMPLE QUERIES (1)
This step demonstrates executing simple XPath Queries against XML documents. Oracle XML DB defines a set of operations that make it possible to query XML content in a very efficient manner. These operations are implemented as a set of methods on the XMLType data-type and as a set of functions that are defined in the SQL/XML standard. Execute the SQL script by clicking on the Icon.

Fig XXIX. Simple SQL Queries against XML content

KEY POINTS :
• The existsNode() SQL/XML operator can be used in the where clause to restrict the set of documents returned by a query. The existsNode() operator 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 which 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 query finds the number of PurchaseOrder documents stored into the Oracle XML DB repository. Since each PurchaseOrder document is stored as a row in the default table defined by the PurchaseOrder XML Schema, the number of documents can be found by counting the number of rows in the PURCHASEORDER table. The second query uses a simple XPath expression and the existsnode() operator to find the number of PurchaseOrder documents where the value of the node /PurchaseOrder/User/text() contains the value “SMITH”.

• •

Page 65 of 116

January 31, 2003

retrieving the entire XML content KEY POINTS : • The value() operator returns the entire contents of the XML Document. The next example shows how a query can return an entire XML document: Fig XXX. which is a table alias mapping to one of the tables referenced in the from clause of the SQL Statement. 2003 . Press any key to complete the SQL*PLUS session.Oracle XML DB Basic Demonstration Press any key to continue execution of the SQL Script. It is used when accessing the content of a row in an XMLType table. Page 66 of 116 January 31. It takes a single argument.

The following query shows how Oracle XML DB can perform queries against collections. 2003 . Fig XXXI. Execute the SQL script by clicking on the Icon.Oracle XML DB Basic Demonstration 4.1 SIMPLE QUERIES (2) This step demonstrates executing more complex XPath Queries against XML documents. querying the contents of Collections Page 67 of 116 January 31. and nodes that are inside collections. The previous queries operated on the values of the text nodes associated with elements which are direct decedents of the root node of the XML document.

Oracle XML DB is able to quickly and efficiently evaluate complex XPath expressions. This means that each document will only be processed once. The result of using the extract() operator on a PurchaseOrder document will be an XML Fragment containing the set of LineItem elements contained in that document The next step is to use the xmlsequence() operator to generate a row from the LineItem elements in each fragment. The extractvalue() operator is used to find the value of the node /PurchaseOrder/Reference/text() in documents that contain a /PurchaseOrder/LineItems/LineItem element where the value of ItemNumber attribute is ‘1’ and the value of the Id attribute for the associated Part element is ‘75515009058’”. 2003 . Finally the query counts the number of rows in the virtual table. • Press any key to complete the SQL*PLUS session. Page 68 of 116 January 31. The next step is to use the SQL table() operator to create a virtual table from the set of rows generated by the xmlsequence() operator. The first query counts the number of LineItem elements in all of the PurchaseOrder documents.Oracle XML DB Basic Demonstration KEY POINTS : • • • Queries are formulated using familiar SQL syntax. The query uses a correlated join between the set of documents in the PURCHASEORDER table and the result generated by the extract() operator. The first step is to use the extract() operator to get the LineItem elements for each PurchaseOrder document. In this example the extractvalue() operator is being used to obtain the value of node /PurchaseOrder/Reference/text() from each document that contains a LineItem element where the value of ItemNumber attribute is ‘1’ and the value of the Id attribute for the associated Part element is “7551500905”. • The second query demonstrates that Oracle XML DB can evaluate complex XPath expressions that reference nodes inside a collection.

Simple Explain plan for existsnode() query Page 69 of 116 January 31. This means that it is extremely important for application developers to analyze their queries and ensure that the query plan chosen is an optimal one. Execute the SQL script by clicking on the Icon. 2003 . can be used with Oracle XML DB.2 EXPLAIN PLAN (1) This step demonstrates that standard SQL query analysis and tuning techniques. Oracle XML DB delivers high performance execution of queries over XML content. This is only possible if the query plans chosen are able to make use of appropriate indexes.Oracle XML DB Basic Demonstration 4. such as explain plan. The first example shows the Explain Plan output generated by the query plan for the query “select the PurchaseOrder documents where the value of the node /PurchaseOrder/Reference/text() is ‘BLAKE-2002100912333601PDT ’”. Fortunately query-rewrite makes it possible to generate conventional query plans for queries that use XPath expressions to query XML content. Fig XXXII.

The next example shows the Explain Plan output generated by the query plan for the query “count the number of PurchaseOrder documents where the value of the node /PurchaseOrder/User/text() is ‘SMITH’”. An implicit filter is added to the query. The REFERENCE_IS_UNIQUE index was created to support the unique constraint that was defined on this node. Fig I. Press any key to continue execution of the SQL Script. Query-Re-write converts the XPath expression into a SQL expression. This will ensure that the response time for this kind of query should be very good.Oracle XML DB Basic Demonstration KEY POINTS : • • • • The query plan shows that the query will be resolved using the Index REFERENCE_IS_UNIQUE. 2003 . This allows the database optimizer to determine that the index used to enforce uniqueness can also be used to resolve the XPath expression. Simple Explain plan for existsnode() query Page 70 of 116 January 31. This filter uses the sys_checkacl() operator to enforce ACL based security using Row Level Security Policies that are generated from the ACL.

The final example shows the Explain Plan output generated for the query “find the value of the node /PurchaseOrder/Reference/text() in documents that contain a /PurchaseOrder/LineItems/LineItem element where the value of ItemNumber attribute is ‘1’ and the value of the Id attribute for the associated Part element is ‘75515009058’”.000’s of documents in the table. This plan may be acceptable when there are only a few hundred documents in the table. Fig XXXIII. but would be unacceptable if there 1000’s or 1.000. 2003 . Press any key to continue execution of the SQL Script. Simple Explain plan for existsnode() operation on collection Page 71 of 116 January 31.Oracle XML DB Basic Demonstration KEY POINTS : • • The query plan shows that the query will be resolved by performing a full table scan of the PURCHASEORDER table.

Oracle XML DB Basic Demonstration KEY POINTS : • • In this example the LineItem elements are stored in an Index Organized Table (IOT). • Press any key to complete the SQL*PLUS session. Page 72 of 116 January 31.000’s of documents in the table. This plan may be acceptable when there are only a few hundred documents in the table. 2003 . It will then use the foreign key value to join back to the PURCHASEORDER table to get the value of the node /PurchaseOrder/Reference/text(). but would be unacceptable if there 1000’s or 1. There is an automatic foreign key relationship between the IOT containing the set of LineItem elements and the PURCHASEORDER Table. The query plan shows that the query will be resolved by performing a full table scan of the IOT containing the LineItem elements.000.

Functional and Text based indexes can be created on any kind of XML document. If the XPath expression can be restated using Object Relational SQL. then the index is created as a conventional B-Tree index on the underlying SQL objects. Oracle XML DB allows the same techniques to be used to ensure optimal response times for queries over XML content. 2003 . During the index creation process Oracle XML DB uses query-rewrite to determine whether or not the XPath expressions included in the Create Index statement can be re-written into equivalent Object Relational SQL expressions. and which is stored using structured storage techniques. If the XPath expression cannot be restated using Object Relational SQL then a functional index is created. Page 73 of 116 January 31.3 CREATE XML INDEXES This step demonstrates how to create indexes on XML content in order to improve query performance. In a conventional relational database the standard way to ensure query response time is to create indexes that allow the query to be resolved in an efficient manner. regardless of whether or not the content is stored using structured storage.Oracle XML DB Basic Demonstration 4. Convention B-Tree indexes can be created on XML content that is XML Schema based. Oracle XML DB allows XPath expressions to be used when creating indexes on XML content. Three kinds of indexes can be created on XML Content.

Oracle XML DB Basic Demonstration Execute the SQL script by clicking on the Icon. Each LineItem element is stored as a separate row in a Nested Table called LINEITEM_TABLE. The create index will result in a B-Tree index being created on the PURCHASEORDER table. The query-rewrite process will use the XML Schema to determine the SQL Object and Attribute that corresponds to this node. • Press any key to complete the SQL*PLUS session. Since a Nested Table is being used to manage the node being indexed the Create Index statement has to be specified in terms of an attribute of the Nested Table. Fig XXXIV. The second index is a compound index on /PurchaseOrder/LineItems/LineItem/@ItemNumber and /PurchaseOrder/LineItems/LineItem/Part/@Id. Indexing XML Content KEY POINTS : • The first index created is on the node /PurchaseOrder/User/text(). In the PurchaseOrder XML Schema the LineItem element is allowed to occur multiple times within a single document. 2003 . Page 74 of 116 January 31.

Execute the SQL script by clicking on the Icon. The first example shows the Query Plan for the query “select the PurchaseOrder documents where the value of the node /PurchaseOrder/Reference/text() is ‘BLAKE-2002100912333601PDT ’” is not changed as a result of creating the new indexes. Fig XXXV. Page 75 of 116 January 31. In a relational database application developers are not required to change their application because the indexes on the data change. This is the expected behavior as that query was already resolved in an optimal manner. This is also true for Oracle XML DB. 2003 .4 EXPLAIN PLAN (2) This step demonstrates how the query plans are improved as a result of indexing the XML content. Simple Explain plan for existsnode() query The next example shows how indexing the node /PurchaseOrder/User/text() alters the query plan for the query “count the number of PurchaseOrder documents where the node /PurchaseOrder/User/text() contains the value ‘SMITH’”.Oracle XML DB Basic Demonstration 4.

Simple XPath Query Plan showing correct use of XPath Index KEY POINTS : • The query plan shows that the query will be resolved using the IPURCHA SEORDERUSER index. 2003 . Fig XXXVI. Page 76 of 116 January 31.Oracle XML DB Basic Demonstration Press any key to continue execution of the SQL Script.

This example shows the query plan generated for the query “find the node /PurchaseOrder/Reference/text() in documents that contain an element /PurchaseOrder/LineItems/LineItem where the value of ItemNumber attribute is ‘1’ and the value of the Id attribute for the associated Part element is ‘75515009058’”. Fig XXXVII. Complex XPath Query Plan showing correct use of XPath Index Page 77 of 116 January 31.Oracle XML DB Basic Demonstration The final example shows how creating a compound index on the attributes ItemNumber and Part.PARTNO of the LINEITEM_TABLE alters the query plan for a query which references those nodes. 2003 . Press any key to continue execution of the SQL Script.

The same skills are still required. From the database administrator’s perspective nothing changes. 2003 .Oracle XML DB Basic Demonstration KEY POINTS : • • • The query will be resolved using the compound index ITEMNUMBERPART. The XMLType and XPath abstractions make it possible for an application programmer to develop applications independently of the underlying storage technology. • • Press any key to complete the SQL*PLUS session. In both cases the syntax used to define the query has not changed. The application did not need re-writing. The new index is used automatically. Create the indexes required to allow queries to execute efficiently. Query-rewrite has allowed the optimizer to analyze the query and determine that the new indexes provide a more efficient way of resolving the queries. Just as with conventional relational applications. Monitor index usage. Page 78 of 116 January 31. creating and dropping indexes makes it possible to tune the performance of an application without having to re-write it. Drop indexes that are not contributing to query performance.

XML This step shows how the HTTP protocol can be used to access content stored in Oracle XML DB using a Path-based (Folder/File) metaphor. Content managed by Oracle XML DB can be accessed and updated using a path-based metaphor. HTTP or WebDAV protocols to access and update content managed by Oracle XML DB. Supporting pathbased access allows client applications. The database will request authentication from the browser before allowing access to the required content. Double-click the icon to launch Internet Explorer and display the target document. such as Microsoft Word or XMLSpy to use the FTP. Fig XXXVIII. who are used to using constructs like URLs and XPath expressions to identify content. Authenticate using the database user-name and password.Oracle XML DB Basic Demonstration 5. 2003 . Authentication Request using path-based access via HTTP and a URL Page 79 of 116 January 31. This allows a URL to be used when accessing or updating content stored in Oracle XML DB.0 BLAKE-2002100912333601PDT. This approach will appeal to XML developers.

Table / Row metaphor the document centric Folder / File metaphor. 2003 . No additional software is required in order to use a browser to access content stored in Oracle XML DB. The protocol support is based on the same architecture as SQL*NET shared server mode. Page 80 of 116 January 31. namely the Oracle Listener and the Multi-Threaded server. The combination of the HTTP protocol server and path-based access mean that. a simple HTTP URL is all that is required to access content. Oracle XML DB allows access to content using both the SQL centric. given the appropriate access permissions.Oracle XML DB Basic Demonstration The PurchaseOrder document identified by the specified URL will be displayed in the browser: Fig I. Support for the HTTP and FTP protocols can be turned off if required • • • Do not close the browser session at this point. Path-based access via HTTP and a URL KEY POINTS : • • Content can be accessed direct from a Web browser using a simple URL.

The XDBUriType datatype makes it easy to use a path to access the content of a document stored on the Oracle XML DB repository. The XDBUriType makes it possible to use a path based metaphor to access content stored in the Oracle XML DB repository. The DBUriType data-type and related DBUri servlet allow a path to be used to identify any row in any table via a path. Execute the SQL script by clicking on the Icon. 2003 . XDBUriType provides a set of methods that make is possible to access different types of contents. Using XDBUriType to access content KEY POINTS • • Path based access to content is also available from SQL.Oracle XML DB Basic Demonstration 5. Oracle XML DB also includes new SQL Operators such as equals_path(). Any path provided to the XDBUriType is assumed to originate at the root of the Oracle XML DB repository. Press any key to complete the SQL*PLUS session. Fig XXXIX. which make it possible to perform pathbased queries against both the PATH_VIEW and the RESOURCE_VIEW . The path-based mechanism for accessing content is also available to the SQL programmer.1 SHOW DOCUMENT (1) This step demonstrates that the File / Folder metaphor can be used to access content when working in SQL. Page 81 of 116 January 31.

2 EDIT DOCUMENT This step demonstrates that WebDAV and FTP support makes it possible to use industry standard tools to access and update content stored in the repository. Editing XML content with Microsoft Word Page 82 of 116 January 31. The path-based metaphor allows applications to access and update content managed by Oracle XML DB. 2003 . The document will displayed in Word Fig XL. The following screen shot shows Microsoft Word using WebDAV to update a row in the PURCHASEORDER table by updating a document stored in the Oracle XML DB repository. Double-click the icon to launch Microsoft Word and open the target document.Oracle XML DB Basic Demonstration 5. If prompted for file conversion or character set conversion select the default values recommended by Word. When prompted enter the required username and password.

Save the changes by opening the File menu and selecting Save . Answer ‘Yes ’ if Word display character conversions dialog when you save the document. Ensure that changes made will result in the document still being a valid PurchaseOrder otherwise it will not be possible to save the updated document. Fig XLI. Updating content with Microsoft Word and WebDAV Page 83 of 116 January 31. Word will use the WebDAV protocol to write the changed document back to the Oracle XML DB repository. 2003 .Oracle XML DB Basic Demonstration Edit the XML document using Microsoft Word.

This means that all of these products will be able to work with content stored in the Oracle XML DB repository. Adobe and Macromedia are incorporating support for the WebDAV protocol in the latest version of their products. When working via a protocol. and uses the revised document to update these objects accordingly. Page 84 of 116 January 31. each PUT or POST request is treated as a separate atomic transaction. such as Altova. Many vendors. • • Close Microsoft Word. Only FTP or WebDAV enabled editors such as WORD/2000 or WORD/XP can be used to edit content stored in the Oracle XML DB repository. This means that changes made to a document via a protocol are visible to other users as soon as the request has been processed. 2003 .Oracle XML DB Basic Demonstration KEY POINTS : • • • The client sends a URL via the appropriate POST or PUT command and then submits the updated document to Oracle XML DB. It is not possible to use editors like NOTEPAD or WORDPAD which do not support the WebDAV and FTP protocols. When Oracle XML DB receives the request it identifies which database objects manage the content associated with the URL.

Updated content visible from SQL KEY POINTS • • Microsoft Word was able to update a document stored in the Oracle XML DB repository. Press any key to complete the SQL*PLUS session. Page 85 of 116 January 31. Execute the SQL script by clicking on the Icon.Oracle XML DB Basic Demonstration 5. 2003 . Each operation performed using a DAV based client is an independent transaction. Fig XLII.3 SHOW DOCUMENT (2) This step shows that the changes made using Microsoft Word are visible from SQL. Changes made using Microsoft Word are immediately visible from SQL.

The second is to use updatexml() to directly update the default table which contains the content of the target document. The RESOUCE_VIEW and PATH_VIEW allow the path-based metaphor to be used when updating content from SQL or PL/SQL. Updating content using updatexml() and EQUALS_PATH(). The join is based on the value of the node /Resource/XMLRef. Since the updatexml() operator is now referencing the content of the default table. This technique can only be used when updating an XML document that is based on a registered XML Schema. the body or content of the document can be accessed or updated via the XPath expression /Resource/Contents. 2003 . query-rewrite can be used to map the updatexml() operation into a set of updates to the underlying SQL object model.Oracle XML DB Basic Demonstration 5. Two techniques can be used to perform path-based updates of content managed by Oracle XML DB from SQL. This means that the update will execute many thousands of times faster. The rows to be updated are identified by joining the PATH_VIEW or RESOURCE_VIEW and the default table. The following example shows updatexml() updating the content of a row in the default table associated with the PurchaseOrder XML Schema. This technique has the advantage that it can be used to access or update any kind of content stored in the XML DB repository. Execute the SQL script by clicking on the Icon.4 UPDATE DOCUMENT This step shows how an XML Document can be updated using SQL. Page 86 of 116 January 31. • Fig XLIII. The updatexml() operator makes it possible to update the content of an XML document. • The first is to use updatexml() to update or replace the content of a document by updating the resource associated with the document. It show s how the updatexml() operator can update a node with-in an XML document be referring to the target node using an XPath expression. The resource is obtained from the RES column in the PATH_VIEW or RESOURCE_VIEW . Once the resource has been located.

Oracle XML DB is able to perform a partial-update. Oracle XML DB performs the update by using DOM methods to update the specified nodes and writing the updated DOM back to the underlying CLOB. and update all of the objects that were derived from the original document with the new content. The resource contains a node /Resource/XMLRef which contains a REF to the XMLType object in the default table that contains the content associated with the resource. Press any key to complete the SQL*PLUS session. This means that the updatexml() operator is still more efficient than using a XML editor. This means that an updatexml() operation will often execute thousands of times faster than a document based update. At any point rollback can be used to back the set of changes made since the last commit. even with nonschema-based XML. Consequently it is necessary to re-parse the entire document. Changes made via updatexml() are not visible to other database users until the transaction is committed. It works with both Schema based and Non-Schema based content. There is no indication of what has changed in the document. In the above example uses the equals_path() operator to identify the target resource. When working from SQL normal transactional behavior is enforced. Multiple updatexml() statements can be used within a single logical unit of work. Using updatexml() to update an XML document is much more efficient then using a text editor like Microsoft Word. attribute or node that is to be updated.Oracle XML DB Basic Demonstration KEY POINTS : • The updatexml() operator can be used to update the contents of an XML document stored as an XMLType. When an editor like Microsoft Word updates an XML document stored in Oracle XML DB the database receives an input stream containing the new contents of the document. An XPath expression is used to identify the element. 2003 . When updatexml() is used to update a schema-based XML document. The update is performed by directly updating the attributes of underlying objects. When updatexml() is used to update a non-schema-based XML document. • • • • • Page 87 of 116 January 31. Query-rewrite is used to translate the updatexml() operation into an equivalent SQL statement.

Using a Web browser to view updated content KEY POINTS • • • 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. Close the browser.Oracle XML DB Basic Demonstration 5.XML This step demonstrates the duality of the SQL and XML approaches. Page 88 of 116 January 31.1 has been closed. XML content can be accessed and updated using a document centric. Changes made using one approach are available to the other approach as soon as the transaction is committed.5 BLAKE-2002100912333601PDT. click this icon to open the browser and display the updated document. 2003 .0 is still open use ctrl-refresh to reload the contents of the browser. file folder metaphor and a SQL centric table / row metaphor. Fig XLIV. If the window from step 5. If the window from step 5.

The XDB account is a locked account. Oracle XML DB also provides new SQL operators that make it possible to efficiently execute path-based queries against the Oracle XML DB repository. Execute the SQL script by clicking on the Icon. The Oracle XML DB Repository is stored in the database schema owned by the user XDB . They can use the equals_path() and under_path() operators to perform path-based queries on the repository.Oracle XML DB Basic Demonstration 6. A SQL programmer can use the RESOURCE_ VIEW and PATH_VIEW to access and update the meta-data and content of documents stored in the Oracle XML DB repository. 2003 . These views can be used just like any other database view.0 RESOURCE VIEW QUERIES (1) This step shows provides more details about the Oracle XML DB repository and shows how SQL programmers can use the RESOURCE_VIEW and PATH_VIEW to query and update the contents repository. The contents of the repository are exposed via the RESOURCE_VIEW and PATH_VIEW . Fig XLV. Simple Queries against the RESOURCE_VIEW Page 89 of 116 January 31. A programmer should never attempt to directly access or update the tables in the XDB schema. Public synonyms make these views available to all database users.

The RESOURCE_VIEW contains one row for each file or folder stored in the XML DB repository. When a non. ANY_PATH is a varchar2 column that contains a valid path that will allow the current user to access the document. When a schema-based XML document is loaded into the Oracle XML DB Repository the content of the document is stored in the default table specified by associated XML Schema. RES is an XMLType column that can be used to access and update the meta-data and content of each • • • document stored in the repository. The content can be accessed via the RESOURCE_VIEW and PATH_VIEW and the XDBUriType data-type. it will return the number of documents that the user issuing the query has read access to. 2003 . The second query uses the under_path() operator to restrict a query to a particular tree within the repository. • Page 90 of 116 January 31.XML file is loaded into the Oracle XML DB Repository the content of the file is stored in the XDB$RESOURCE table. In this example the count(*) operator will count the number of files and folders beneath the folder /home/SCOTT/purchaseOrders. It consists of two columns. This query will not return the total number of documents stored in the repository. • The first query uses the count(*) operator to count the number of objects currently stored in the Oracle XML DB repository. The content can be accessed via the RESOURCE_VIEW and PATH_VIEW and the XDBUriType data-type. The majority of the meta-data is stored in a table called XDB$RESOURCE.Oracle XML DB Basic Demonstration KEY POINTS : • • The meta-data for each file and folder in the Oracle XML DB Repository is maintained in the tables in the XDB Schema. When a non-schema-based XML document is loaded into the Oracle XML DB Repository the content of the document is stored in the XDB$RESOURCE table. Typically these tables are located in the database schema owned by the user registering the XML Schema.

xsd. The following example shows the XML representation of the standard set of meta-data properties for the folder /home/SCOTT/purchaseOrders. 2003 .Oracle XML DB Basic Demonstration Press any key to continue execution of the SQL Script. Fig XLVI. queried and updated just like any other XML document stored in Oracle XML DB. Viewing a Resource Page 91 of 116 January 31. Oracle XML DB maintains the meta-data for each resource as an XML document. It also defines that a WebDAV server and a DAV enabled client will exchange meta-data as an XML document. The IETF WebDAV standard defines the set of meta-data properties that a WebDAV server is expected to maintain for each resource. A resource documents can be accessed. This document is compliant with the XML Schema XDBResource.

This example shows uses the equals_path() operator makes it possible to locate a document based on a path. Fig XLVII.oracle. In order to access a document a minimum of read privilege is required. • The repository provides very rudimentary versioning capabilities for non-schema-based XML and other nonXML files.Oracle XML DB Basic Demonstration KEY POINTS : • The meta-data for each file or folder is persisted as an XML document called a resource. The resource document is compliant with the XML Schema registered under the URL http://xmlns.xsd . DELTA-V . Creator. 2003 . . Owner. The resource documents contain standard meta-data such as Display Name. The next example shows the under_path() operator and the PATH_ VIEW being used to find the set of documents in a particular folder.com/xdb/XDBResource. Each document in the Oracle XML DB repository is protected by an ACL which grants or revokes permissions from a database user or role. • • Press any key to continue execution of the SQL Script. Querying the Folder Hierarchy Press any key to complete the SQL*PLUS session. A future release of Oracle XML DB will support version of schema-based XML and the WebDAV versioning specification. ACL based security is enforced through Row -Level Security when repository content is accessed from SQL. The current implantation of ACLs is compliant with the WebDAV ACL standard. Creation Date and Last Modification Date. Page 92 of 116 January 31. The content of a resource is defined by the WebDAV standard.

2003 . Querying the Resource KEY POINTS : • The first query finds a path to each XSL style sheet stored in the Oracle XML DB repository. and the like condition restricts which documents in the tree are returned.Oracle XML DB Basic Demonstration 6. The under_path() operator restricts which tree is searched. This content of the resource document can be accessed and updated using any of the SQL/XML operators. It finds the set of documents by using a SQL ‘like’ query on the contents of the node /Resource/DisplayName to find documents with names that end with the file extension ‘. Fig XLVIII. extractvalue() and updatexml() .1 RESOURCE VIEW QUERIES (2) This demonstrates further queries against the XML DB repository and the use of the Hierarchical Index feature to efficiently resolve path based queries. • • Page 93 of 116 January 31. The second query finds the path to all the documents under the folder /home/SCOTT/purchaseOrders that starts with ‘ADAMS’. like existsnode() . The first example demonstrates some simple queries against the meta-data contained in the RESOURCE_VIEW Execute the SQL script by clicking on the Icon.xsl’.

such a filename or owner. using the node /Resource/XMLRef . In this example the path returned by the query forms the local part of a URL which can be used to access the document directly from a web browser. which is stored in the RESOURCE_VIEW . The next example demonstrates how to locate a document based on a join between the table containing the content of a schema-based XML document. and the meta-data associated with the document. 2003 . Fig XLIX. • • Page 94 of 116 January 31.Oracle XML DB Basic Demonstration Press any key to continue execution of the SQL Script. The results of this query are joined with the RESOURCE_VIEW . The ability to perform joins between the RESOURCE_VIEW and the default tables is extremely important as it allows a developer to create queries that include conditions based on meta-data. Joining meta-data and Content KEY POINTS : • In this example the query on the PURCHASEORDER table locates the set of documents that contain an order for the Part whose ‘Id’ is 75515009058. The RESOURCE_VIEW is then used to obtain a valid path to each of the documents that contained an order for the part. and content.

path-based queries become very inefficient as the depth of the hierarchy increases. Press any key to complete the SQL*PLUS session. Fig L. Combing the ability to have a query return a URL with the Oracle XML DB HTTP server greatly simplifies the process of writing Web based applications. This is the same technique that is used to add support for text indexing and many other advanced index types to the database. The Hierarchical Index allows path based queries to be resolved without having to utilize expensive connect by operations. The hierarchical index is implemented as an Oracle domain index. The reason for this is that performing a path-based query in a relational database typically requires a ‘connect by’ operation. Oracle XML DB introduces a new index called the hierarchical index. Connect by queries are one of the most difficult queries for a traditional relational database to resolve in an efficient manner. The following example shows the explain plan output for a path-based query. Explain plan for path-based query showing use of Hierarchical Index KEY POINTS : • • • The hierarchical index is used to resolve the path-based query. 2003 . Page 95 of 116 January 31. This index allows the database to resolve a path-based query without using a ‘connect by’ operation. This means that path-based queries are resolved in an extremely efficient manner. Using conventional relational techniques.Oracle XML DB Basic Demonstration Press any key to continue execution of the SQL Script.

creating a simple relational view over an XMLType table KEY POINTS : • • • • Relational views can be used to expose the contents of an XML document as a row. but understand the Oracle database. This means that tools. applications and programmers who have no understanding of XML. Fig LI. can now work with XML content. Each row in the view will contain information from one document in the PURCHASEORDER table. Page 96 of 116 January 31. Execute the SQL script by clicking on the Icon.0 MAKE VIEWS This step demonstrates how to expose the contents of XML documents relationally.Oracle XML DB Basic Demonstration 7. stored in the database through conventional relational views. Views created this way look and behave like a normal relational view. Oracle XML DB makes it possible to expose XML content. 2003 . The example shows how to create a view where each row in the view contains data from nodes that occur only once in each XML document. This example creates a view called PURCHASEORDER_MASTER_VIEW. The view defines a set of columns and the XPath expressions required to map between the nodes in the document and the columns in the view. The view definitions use the SQL/XML operators and XPath expressions to map between the nodes in the XML document and the columns in the view.

This example creates a view called PURCHASEORDER_DETAIL_VIEW. Press any key to complete the SQL*PLUS session. Each row will consist of a single XMLType. The view is based on a virtual table that is created using the SQL table().Oracle XML DB Basic Demonstration Press any key to continue execution of the SQL Script. 2003 . The view defines a set of columns and the XPath expressions required to map between the nodes in the document in the virtual table and the columns in the view. The virtual table will contain one row for each element in the target collection. The xmlsequence()operator takes the XML fragment and generates a separate row from each top level node in the fragment. The fragment will contain the set of nodes that match the XPath expression passed to the extract() operator. This ensures that the query does not generate a Cartesian product. In this case the fragment will contain the set of LineItem elements present in the PurchaseOrder document. A fragment is an XML document that contain more than one root node. Fig LII. The set of rows generated by the xmlsequence() operator are based to the SQL table() operator. xmlsequence() and extract() operators. The table() operator generates a virtual table from the set of rows generated by xmlsequence() . There is an implicit correlated join between the base table and the argument passed to extract() operator. The fragment is passed to the xmlsequence() operator. The next example shows a more complex view that uses SQL/XML operators to expose the set of elements in a collection as a set of rows in a relational view. Each LineItem will appear as a top level node. creating a simple relational view over a XML collection KEY POINTS : • • • • • Relational views can be used to expose the contents of a collection of elements in an XML document as a set of row. The virtual table is created as follows The first step is to use the extract() operator to generate an XML fragment from each document in the PURCHASEORDER table. There will be one row in the view for each LineItem element in each document in the PURCHASEORDER table. Views created this way look and behave like a normal relational view. Page 97 of 116 January 31.

These are standard relational queries that any user familiar with the Oracle database can execute. using a view to perform simple relational queries over XMLType content KEY POINTS : • The first query shows a simple query against the master view. 2003 .Oracle XML DB Basic Demonstration 7. The next example shows how the views allow simple relational queries to be executed on XML content. Execute the SQL script by clicking on the Icon. Query-rewrite will ensure that.1 QUERY VIEWS This step demonstrates that Relational Views over XML look and behave like Relational Views over other data. There is no XML specific syntax in either the query syntax or the generated result set. Since the views look and act like standard relational views they can be queried using standard relational syntax. • • Page 98 of 116 January 31. The second query shows a query based on a join between the master view and the detail view. Fig LIII. queries against the relational view are resolved as quickly as queries against the underlying tables. for schema-based XMLType tables.

For example.I. features. are not XML aware they are able process XML content exposed through a relational view. there are 7 PurchaseOrders where 1 copy of the item is ordered and 2 PurchaseOrders where 4 copies of the item are ordered. 2003 . such as the Business Intelligence and Analysis capabilities. Page 99 of 116 January 31. The query performs an analysis of the PurchaseOrder documents to determine the number of copies of each title that are being ordered on each PurchaseOrder. • Press any key to complete the SQL*PLUS session. The following screen shot shows a simple business intelligence query being executed on XML content.Oracle XML DB Basic Demonstration Press any key to continue execution of the SQL Script. such as rollup and cube. looking at PurchaseOrders that contain an order fro part ’715515009058’. Using a relational view to perform complex SQL queries on XML content KEY POINTS : • Exposing XML content as through relational view makes it possible to apply many of the advanced features of the Oracle 9i database. Even though the B. to XML content. Fig LIV.

Using SQL/XML operators to create an XMLType View over relational content Page 100 of 116 January 31. 2003 . Execute the SQL script by clicking on the Icon. The next example demonstrates using the XML generation operators defined by the SQL/XML standard to create a simple XML document based on the content of the relational tables EMP and DEPT.Oracle XML DB Basic Demonstration 7. Oracle XML DB allows these operators to be used to define XMLType views. The SQL/XML standard includes new operators that allow a SQL query to generate a set of XML documents. This makes it possible to persistently view relational content as XML. rather than a SQL result set. Fig LV. Creating XMLType views over relational content make to possible to access and update relational content using an XML Metaphor.2 MAKE XML VIEW This step demonstrates using the operators defined the SQL/XML standard to access relational content as XML documents.

This means that the query-plan for a query that returns data as a set of XML documents may be different from a query that returns the same data as a tabular result set. The xmlforest() operator is so named because it contains a collection of “TREES”… Oracle implements the SQL/XML operators as part of the core database kernel. column will appear as the employeeNumber attribute of the Employee element. Using DOM to process a large SQL result set requires significant amounts memory and processing overhead. The operators fall into two distinct categories: Operators that make it possible to insert. There will be on Employee element for each row in the The contents of the • EMPNO EMP table that is related to the current DEPT row. This allows the database to optimize query-plans based on the shape of the generated XML. The EmployeeList element will contain a collection of Employee elements. IBM and Microsoft are all actively involved in the development of the SQL/XML standard. Other vendors implement the SQL/XML operators in a less efficient manner. Press any key to complete the SQL*PLUS session. The view that provides a persistent XML representation of the contents of the DEPT and EMP tables. Operators that make it possible to generate a set of XML documents using a SQL statement. by post-processing a conventional SQL result set using DOM API’s and then printing the DOM. update and query XML documents inc the context of a SQL statement. EmployeeList. They make it easy to generate any shape of XML using a SQL statement. This is much less efficient than Oracle’s approach for a number of reasons: The database is not able to take the SQL/XML operators into account when determining the query plan for a given SQL statement. xmlattibutes(). The most commonly used SQL/XML operators are xmlelement().Oracle XML DB Basic Demonstration KEY POINTS : • SQL/XML is an ANSI/ISO standard that defines a set of XML specific SQL operators. Rows in an XMLType view can be persisted as documents in the Oracle XML DB repository. • The example shows using the SQL/XML functions to define an XMLType called DEPARTMENT_XML. Page 101 of 116 January 31. There will be one XML document for each row in the DEPT table. • • node will contain three child elements called Name and Location and The contents of the Name element will come from the DNAME column in the DEPT table and the contents of the Location element will come from the LOC column in the DEPT table. Oracle. • The SQL operators for generating XML are extremely flexible. The root node of each document will be The Department Department. xmlforest() and xmlagg() . 2003 . EMP The contents of other columns in the table will appear as children of the Employee element.

Oracle XML DB Basic Demonstration 7. etc) of the generated document is defined by the SQL/XML operators used in the create view statement. Press any key to complete the SQL*PLUS session. Fig LVI. Querying an XMLType using XML metaphors KEY POINTS : • • • The XMLType view DEPARTMENT_XML exposes the contents of the DEPT and EMP tables as a set of XML documents. 2003 . In this case the XPath expression restricts the result set to the documents where the node /Department/Name/text() contains the value ‘ACCOUNTING ’. Execute the SQL script by clicking on the Icon. Documents in an XMLType view can be queried using the SQL/XML operators. There will one XML document for each row in the DEPT table. Page 102 of 116 January 31. attribute names. The shape (element names.3 Query XML Views This step demonstrates querying relational content using an XMLType view and XPath expressions. This example shows a simple query against the DEPARTMENT_XML XMLType view.

Double-click the icon to launch Internet Explorer. When the Browser opens click on the Favorites menu and select the “XML DB Basic Demo ” item. Fig LVII. 2003 . This menu contains the set of internet short-cuts required to complete this step of the demonstration.Oracle XML DB Basic Demonstration 8. DBUri servlet examples Do not close the browser.0 DBURI AND XSL EXAMPLES This step demonstrates the use of the DBUri servlet and the ability of Oracle XML DB to perform XSL Transformations. Page 103 of 116 January 31.

in this case With a simple URL the entire contents of the table are returned as a single XML Document.Oracle XML DB Basic Demonstration 8. in this case The name of the table. Fig LVIII. The URL uses a Schema / Table metaphor in place of the conventional Folder / File metaphor. The DBUri data-type allows rows in a relational table to be exposed as a set of XML documents using a simple URL. The definition of the ROW element is derived from the set of columns in the target table. The name of the root element that encloses the set of ROW elements is derived from the name of the target table. Using the DBUri servlet to access relational content KEY POINTS : • The local part of the URL used to access the table is constructed as follows: The virtual root of the DBUri servlet. /oradb.0.0 Demo item. The DBUri servlet allows a simple URL to be used to view the entire contents of any table in an Oracle database as a single XML document. 2003 .1 CONTENT OF DEPT TABLE This step demonstrates using the DBUri servlet to view the content of a relational table as an XML document. The following example shows the results using the DBUri servlet to access the contents of the DEPT table: Click on the Favorites menu. in this case • • • DEPT. Do not close the browser. Click on the 9.2. SCOTT.1 Contents of DEPT Table ’. The Oracle XML DB HTTP server and DBUri servlet allow the functionality of the DBUri data-type to be accessed directly from any browser that supports XML. Each row in the table becomes a complex element called ROW. The name of the owner of the database schema that contains the table.2. This value is configurable. Select the item ‘ 8. Page 104 of 116 January 31.

2 Department number for CHICAGO and NEW YORK’. DEPTNO column for rows that where the LOC Click on the Favorites menu. Fig LIX. The URL passed to the DBUri servlet can also include parameters that provide control over the features like the name of the root element. The URL can also be used to control which columns are included in the output generated by the servlet. Click on the 9. Page 105 of 116 January 31.. using a complex URL to control content and formatting KEY POINTS : • • • The URL uses the XPath notation generated XML document.2. [LOC=”CHICAGO” or LOC=”NEW YORK”] to limit which rows are included in the ROW[.2. or the mime type of content being generated. The URL uses the XPath notation document.2 D EPARTMENT NUMBER FOR CHICAGO AND NEW YORK This step demonstrates how a more complex URL make it possible to control the XML generated by the DBUri servlet. 2003 .0 Demo item.]/DEPTNO to limit which columns are included in the generated The URL uses the rowsettag parameter to specify the name of the root element of the generated document. The URL passed to the DBUri servlet controls the content of the generated XML document.0. The DBUri servlet allows XPath expressions to be used to subset which rows in the table are returned.Oracle XML DB Basic Demonstration 8. Select the item ‘ 8. Do not close the browser. The following example shows using the DBUri servlet to display the column contains the values ‘Chicago ’ or ‘New York ’.

Oracle XML DB Basic Demonstration 8. 2003 . In the case of an XMLType the URL is allowed to reference any node in the document. When accessing XML content the URL can contain XPath notations which control which documents are returned and which nodes are included. Page 106 of 116 January 31.3 PURCHASE ORDER RAW XML This step demonstrates using the DBUri servlet to view the content of an XMLType table.

The document generated by the DBUri servlet will only include documents where the node /PurchaseOrder/Reference/text() contains the value ‘BLAKE-2002100912333601PDT. using the DBUri servlet to access XML content KEY POINTS : • • The URL uses the DBUri servlet to access the document as a row in the resource in the XML DB repository. the DBUriServlet allows an XPath expression to be used to determine which rows in the table are returned. Select the item ‘ 8. PURCHASEORDER table rather than as a When accessing an XMLType table or XMLType view. Click on the 9. Page 107 of 116 January 31. 2003 .2.0 Demo item.3 Purchase Order Raw XML’.XML”]?contenttype=text/xml Click on the Favorites menu.0. The full http://localhost:8080/oradb/SCOTT/PURCHASEORDER/ROW/PurchaseOrder[Reference=“BLAKE2002100912333601PDT.Oracle XML DB Basic Demonstration The following example shows the DBUri servlet being used to access a row in the URL is as follows: PURCHASEORDER table.XML’ The contenttype parameter is used to set the mime-type of the generated document to text/xml. Fig LX.2. This is very similar to the functionality provided by the W3C XPOINTER standard. • • Do not close the browser.

0. Page 108 of 116 January 31. Using the DBUri servlet to access an XMLType view KEY POINTS : • • The rowsettag parameter is used to set name of the root element of the generated document. Click on the 9. Fig LXI. The XMLType view makes it possible view relational content directly from a web browser. 2003 .4 D EPARTMENT VIEW RAW XML This step demonstrates using the DBUri servlet to view the content of an XMLType view.4 Department View Raw XML’. Do not close the browser. The following example shows the DBUri servlet being used to access a row in the URL is as follows: DEPARTMENT_XML view.2.2.Oracle XML DB Basic Demonstration 8. The full http://localhost:8080/oradb/SCOTT/DEPARTMENT_XML/?contenttype=text/xml&rowsettag=Depart ments Click on the Favorites menu. Select the item ‘ 8.0 Demo item.

Fig LXII. Click on the 9. another style sheet could format the same document for display on a WAP enabled phone. This example will show an XSLT style sheet that can be used to transform a PurchaseOrder document into HTML. Do not close the browser.2. Click on the Favorites menu. compliant with the W3C XSLT standard.2. For instance one style sheet could format a document for display in a PC Browser. The standard mechanism for converting an XML document into HTML is to perform an XSL transformation using a style sheet. XSL transformation makes it possible to separate display logic from data and processing logic. Different Style sheets can be used to format a given XML document different ways. These is nothing Oracle XML DB specific about the styles sheet The style sheet is simply stored as non-schema based XML inside the Oracle XML DB repository. Standard W3C XSL style sheet stored in Oracle XML DB repository.5 Purchase Order Stylesheet’.0 Demo item. Select the item ‘ 8. In this example the style sheet has been loaded into the Oracle XML DB repository so it can be accessed directly from a web browser using a simple URL.0. Page 109 of 116 January 31. They want to view data using a standard web browser. KEY POINTS : • • The style sheet is an absolutely standard XSL style sheet. Most end-users do want to deal with XML.5 PURCHASE ORDER STYLE SHEET This step shows how the Oracle XML DB repository can manage all of the different kinds of documents needed to work with XML content. 2003 .Oracle XML DB Basic Demonstration 8. as part of a neatly formatted HTML page.

the first step is to create a DOM from the XML document. The processor takes the XML. When using the DBUri servlet to perform XSLT processing it is good practice to use the contenttype parameter to explicitly specify the mime type of the generated output. These optimizations are particularly effective when the generated HTML incorporates information from multiple XML documents.Oracle XML DB Basic Demonstration 8. The following example shows the DBUri servlet being used to transform a row in the URL is as follows: PURCHASEORDER table.XML”]?contenttype=text/html?&transform=/home/SCOTT/ poSource/ xsl/po. By performing XSL transformation inside the database. as only the parts of the XML document required in order to perform the XSL transformation are loaded into the DOM. In order to create HTML from XML. The DOM representation of an XML document can be several times the size of the original document. The result of the transformation is also expected to be a valid XML document..6 PURCHASEORDER WITH XSL TRANSFORMATION This step demonstrates using Oracle XML DB to generate HTML documents from XML documents using XSL Transformation. When transforming schema-based XML content the XSLT processor works off an instance of the lazily loaded virtual DOM. the first is the XML document to be transformed. The SQL developer invokes the XSLT processing using the xmlTransform() operator. Memory usage is reduced. such as HTML. particularly in cases where only a small part of the source document is going to be included in the generated output. The DOM is loaded directly from disk eliminate the need to perform XML parsing. Page 110 of 116 January 31. This means that XSLT transformation can be very in-efficient. 2003 . The full http://localhost:8080/oradb/SCOTT/PURCHASEORDER/ROW/PurchaseOrder[Reference=“BLAKE2002100912333601PDT. The easiest way to make a style sheet available to the xmlTransform() operator is to store it as a document in the Oracle XML DB repository and then access it via the XDBUriType data-type. and the instructions contained in the style sheet and uses them to generate HTML. an XSLT processor is required. The DOM is then passed to XSL processor which uses the DOM API to process the information contained in the document and format it as HTML. These optimizations greatly reduce the amount of parsing and memory overhead associated with performing XSL Transformation. With a conventional XSL processor. This allows the XML generated by the DBUri servlet to be presented to in a more user friendly manner. The act of parsing the XML document and creating the DOM is processor intensive. Oracle XML DB includes a database resident XSLT processor that can be used to perform XSL transformation. A paging mechanism is used to manage the overall size of the DOM. The DBUri servlet can invoke the database’s XSLT processor. Both parameters are XMLType. XSL transformation is based on the DOM memory Model. The style sheet is applied directly to the generated XML before the document is returned to the browser. the XSLT processor can leverage Oracle XML DB features like the Lazily Loaded DOM. the second if the XSL style sheet which defines the transformation. This means the HTML document generated by the transformation must be a valid XHTML document.xsl The following screen shot shows how an XSL Transformation can be applied to XML content using the DBUri Servlet. The xmlTransform() operator takes two arguments.

Oracle XML DB Basic Demonstration Click on the Favorites menu.0.2. In this example the URL passed to the DBUri servlet will retrieve one PurchaseOrder document from the PURCHASEORDER table. • • Do not close the browser. The style sheet processing is performed by the XSLT processing incorporated into the database.2. Select the item ‘ 8. The transformation will be performed using the style sheet /home/SCOTT/poSource/xsl/po.6 PurchaseOrder with XSL Transformation’.Database XSL transformation of a PurchaseOrder using the DBUri Servlet. Fig LXIII. Page 111 of 116 January 31. The XSLT processor can also be invoked from SQL using the transform() method provided by XMLType datatype or the SQL xmlTransform() operator.xsl. KEY POINTS : • • • • Style sheet processing is initiated by adding a transform parameter to the URL passed to the DBUri Servlet. The DBUri servlet will use the xmlTransform() operator to convert the PurchaseOrder document from XML to HTML before returning it to the browser. 2003 .0 Demo item. The value of the transform parameter is a URI that references a style sheet stored in the database. Click on the 9.

0. KEY POINTS : • • The style sheet is an absolutely standard XSL style sheet. Fig LXIV. Select the item ‘ 8. Do not close the browser.0 Demo item. Click on the 9.2. 2003 . Click on the Favorites menu.Oracle XML DB Basic Demonstration 8. These is nothing Oracle XML DB specific about the styles sheet The style sheet is simply stored as non-schema based XML inside the Oracle XML DB repository.2. Page 112 of 116 January 31.7 D EPARTMENT VIEW S TYLE SHEET This step shows an XSL style sheet that can transform the contents of the DEPARTMENT_XML view into a neatly formatted HTML page that can be viewed in any web browser.7 Department View Stylesheet’. Standard W3C XSL style sheet stored in Oracle XML DB repository.

No application coding was required to generate the HTML page.2. an XSLT style sheet and a simple URL to publish relational content directly from the database to a web browser. Click on the 9.0 Demo item.2. No procedural coding.Oracle XML DB Basic Demonstration 8. servlets. 2003 .8 D EPARTMENT VIEW WITH XSL TRANSFORMATION This step demonstrates using XMLType views and XSL transformation to views the contents of the tables directly from a web browser.0. EMP and DEPT The combination of XMLType views and XSL transformation make it possible to use a simple SQL statement. Fig LXV. or other mid-tier components need to be created or installed in order to achieve this functionality. Click on the Favorites menu. KEY POINTS : • • The generated HTML page displays the contents of the EMP and DEPT tables as an HTML document.8 Department View with XSL Transformation’. Close the browser. Select the item ‘ 8. The page was generated by applying an XSLT style sheet to a set of documents that were created using the SQL/XML operators. Page 113 of 116 January 31.Database XSL transformation of EMP and DEPT using the DBUri Servlet.

Using Oracle Text to index and query a schema-based XMLType Page 114 of 116 January 31.Oracle XML DB Basic Demonstration 9. Fig LXVI. Execute the SQL script by clicking on the Icon. 2003 .0 ORACLETEXT EXAMPLES This step demonstrates how oracleText functionality be applied to XML content that has been stored in Oracle XML DB using stored using Structured Storage techniques.

2003 .Oracle XML DB Basic Demonstration KEY POINTS • • • Oracle XML DB allows oracleText indexes to be created on XML content that has been stored in the database using Structured Storage Techniques. can be used to speed up the existsNode() function. • • Page 115 of 116 January 31.ctxxpath . This is much faster than performing a functional evaluation of every document in the table. The example shows creating a full text (ctxsys. If no such index exists it will perform a functional evaluation of each document in the table to see if it contains a node which matches the supplied XPath expression. If a ctxsys. The first.ctxxpath index has been created then existsNode() will use this index as a primary filter when resolving an XPath expression that cannot be resolved with a B-Tree or Functional Index. There are two kinds of text index that are allowed. By default existsNode() looks for a B-Tree or Functional index than can be used to resolve the query. ctxsys.context allows for full text search across XML content. The second.context) index on the PURCHASEORDER table and then using the oracleText contains() function to perform text based search over the PurchaseOrder documents. ctxsys.

Shutdown the database. 3. The tnsnames. Add the LOCAL_LISTENER entry to the init.ora and define a TNS Alias that points at the target Listener.ora file and add an entry in the form LOCAL_LISTENER=TNSAlias 5. Use sqlplus to verify that is possible to connect to the database using the specified TNSAlias sqlplus scott/tiger@TNSAlias 4. Restart the database.ora file is in the pfile directory associated with instance.ora file used to configure the database. Rebuild the spfile by connecting as sys and executing the command: create spfile from pfile = ‘init.ora file. Edit the init. 2003 . 6. The TNS Alias must be defined in the tnsnames. Save the changes to init. The value of the LOCAL_LISTENER parameter is a TNS Alias that will connect to the target listener. 1. Save the changes to the tnsnames. 8. Verify the that the target Listener is now providing HTTP and FTP services on the desired ports using the command lsnrctl sta tus LISTENER_NAME Page 116 of 116 January 31.ora file. 7.ora file on the machine hosting the Listener.Oracle XML DB Basic Demonstration APPENDIX I: CONFIGURING A LOCAL LISTENER A Local Listener is required when the Listener that will be servicing the Oracle XML DB database is not running on the default port of 1521.ora file is located in the directory <ORACLE_HOME>/network/admin A Local Listener is configured using the following steps. The Local Listener is configured by modifying the init. The default location for the init. and specifies the Service name for target database instance. Edit tnsnames. The following example defines a TNS Alias called XDB that will connect to a database service called ORCLXDB using the TNS listener servicing port 1522 XDB = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1522)) (CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAM E = ORCLXDB)) ) 2.ora’.ora file used to configure the database.

Sign up to vote on this title
UsefulNot useful