Oracle XML Basic Demo

Embed Size (px)

Citation preview

  • 8/8/2019 Oracle XML Basic Demo

    1/116

    Oracle XML DB Basic Demonstration

    Page 1 of 116 January 31, 2003

    OORRAACCLLEEXXMMLLDDBBDDEE MMOOSSCCRRII PPTT ((99..22..00..22..00))

    Pre-requisites ...................................................................................................................................................................................................4Non Oracle Software...............................................................................................................................................................................4Oracle Software.........................................................................................................................................................................................4

    Installing the Demonstration......................................................................................................................................................................5Installation Parameters ............................................................................................................................................................................5Database, Oracle Net Services and XML DB Configuration.......................................................................................................6XML DB protocol configuration.........................................................................................................................................................7TNS Listener Configuration..................................................................................................................................................................8Verify XML DB protocol configuration and connectivity............................................................................................................9Verify SQL*NET and XML DB Configuration..............................................................................................................................9Configuring the demonstration installation.....................................................................................................................................11Completing the demonstration installation......................................................................................................................................12

    What is the Oracle XML Database?.......................................................................................................................................................13Oracle XML DB Major Features.............................................................................................................................................................14

    XMLType..................................................................................................................................................................................................15XML Schema...........................................................................................................................................................................................18

    Namespaces.........................................................................................................................................................................................18XML Schema and Namespaces......................................................................................................................................................18Registering an XML Schema...........................................................................................................................................................19DOM Fidelity......................................................................................................................................................................................20Annotating an XML Schema..........................................................................................................................................................20Identifying and Processing Instance Documents......................................................................................................................20Structured Vs Unstructured Storage.............................................................................................................................................21

    XML / SQL Duality ..............................................................................................................................................................................23SQL/ XML...........................................................................................................................................................................................23XPath and Query Re-write ..............................................................................................................................................................25

    XML DB Repository..............................................................................................................................................................................27The Oracle XML DB Protocol Architecture..............................................................................................................................31

    Programmatic Access.............................................................................................................................................................................32Oracle XML DB performance.................................................................................................................................................................33

    XML Storage Requirements.................................................................................................................................................................33XML Memory Management ................................................................................................................................................................33XML Parsing Optimizations................................................................................................................................................................34Node Searching Optimizations...........................................................................................................................................................34

  • 8/8/2019 Oracle XML Basic Demo

    2/116

    Oracle XML DB Basic Demonstration

    Page 2 of 116 January 31, 2003

    XML Schema Optimizations ...............................................................................................................................................................34Load Balancing ........................................................................................................................................................................................34Non-Native Code...................................................................................................................................................................................35Type Conversions...................................................................................................................................................................................35

    XML Manageability.....................................................................................................................................................................................36Performing the demonstration.................................................................................................................................................................37

    0.1 Initial Setup (Run Once) ................................................................................................................................................................380.2 Reset Demo.......................................................................................................................................................................................381.0 XML DB Repository.......................................................................................................................................................................391.1 Make Directories..............................................................................................................................................................................421.2 Oracle XML DB Protocol Architecture ....................................................................................................................................451.3 Load Configuration Files ...............................................................................................................................................................462.0 Show XML Schema.spp.................................................................................................................................................................47

    Creating and Editing an XML Schema.........................................................................................................................................47Annotating an XML Schema..........................................................................................................................................................51

    2.1 Register Schema................................................................................................................................................................................532.2 Show Objects....................................................................................................................................................................................543.0 Load Sample Data............................................................................................................................................................................563.1 Add Constraints................................................................................................................................................................................593.2 Duplicate Reference........................................................................................................................................................................613.2 Invalid User .......................................................................................................................................................................................623.3 Invalid Document ............................................................................................................................................................................634.0 Simple Queries (1)............................................................................................................................................................................654.1 Simple Queries (2)............................................................................................................................................................................674.2 Explain Plan (1) ................................................................................................................................................................................694.3 Create XML Indexes.......................................................................................................................................................................734.4 Explain Plan (2) ................................................................................................................................................................................755.0 BLAKE-2002100912333601PDT.XML....................................................................................................................................795.1 Show Document (1)........................................................................................................................................................................815.2 Edit Document.................................................................................................................................................................................825.3 Show Document (2)........................................................................................................................................................................855.4 Update Document ...........................................................................................................................................................................865.5 BLAKE-2002100912333601PDT.XML....................................................................................................................................886.0 Resource View Queries (1)............................................................................................................................................................896.1 Resource View Queries (2)............................................................................................................................................................937.0 Make Views........................................................................................................................................................................................96

  • 8/8/2019 Oracle XML Basic Demo

    3/116

    Oracle XML DB Basic Demonstration

    Page 3 of 116 January 31, 2003

    7.1 Query Views......................................................................................................................................................................................987.2 Make XML View...........................................................................................................................................................................1008.0 DBURI and XSL Examples.......................................................................................................................................................103

    8.1 Content of DEPT Table.........................................................................................................................................................1048.2 Department number for CHICAGO and NEW YORK..............................................................................................1058.3 Purchase Order Raw XML....................................................................................................................................................1068.4 Department View Raw XML................................................................................................................................................1088.5 Purchase Order Style sheet ....................................................................................................................................................1098.6 PurchaseOrder with XSL Transformation........................................................................................................................1108.7 Department View style sheet ................................................................................................................................................1128.8 Department View with XSL Transformation...................................................................................................................113

    9.0 OracleText examples....................................................................................................................................................................114Appendix I: Configuring a Local Listener.....................................................................................................................................116

  • 8/8/2019 Oracle XML Basic Demo

    4/116

  • 8/8/2019 Oracle XML Basic Demo

    5/116

    Oracle XML DB Basic Demonstration

    Page 5 of 116 January 31, 2003

    INSTALLING THE DEMONSTRATION

    To install the XDB basic demo unzip the file XDBBasicDemo.zip into a folder of your choice. After unzipping this filethe target folder should contain a subfolder called basicDemo. Ensure that there are no space characters in the paththat leads to the basicDemo folder. Open a Windows Command Prompt session in this directory.

    INSTALLATION PARAMETERSThe 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 hostname or IP address of the machine that is hosting the target TNS Listener.

    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. The default for this value 1521.

    The SERVICE_NAME of the target database instance.

    A TNS alias that will establish Oracle Net Services connections to the target database and listener.

    The port numbers used by the Oracle XML DB protocols to service HTTP and FTP requests, The default valuesare 8080 (HTTP), and 2100 (FTP).

    The username and password that will be used when giving the demonstration. This user must have been grantedconnect and resource privileges.

  • 8/8/2019 Oracle XML Basic Demo

    6/116

    Oracle XML DB Basic Demonstration

    Page 6 of 116 January 31, 2003

    DATABASE ,ORACLE NET SERVICES AND XMLDBCONFIGURATION Before starting the installation verify that Oracle Net Services, FTP and HTTP are all correctly configured using thefollowing steps.

    Open a Windows Command Prompt session, and set the working directory to be bas icDem o / Ins ta l l . StartSQL*PLUS, and the script xdbConfiguration.sql. This script must be run as user SYS

    Fig I. running the xdbConfiguration.sql script

  • 8/8/2019 Oracle XML Basic Demo

    7/116

    Oracle XML DB Basic Demonstration

    Page 7 of 116 January 31, 2003

    If XML DB is correctly installed this should cause the XML DB configuration summary document to be displayed.This should look like the following example.

    ORCL9202.xp.mark.drake.oracle.com

    MDRAKE-LAP

    Note that the above example shows the default XDB port numbers which are set when XML DB is installed and maynot match the values in your environment.

    XMLDB 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 followsFor FTP:

    SQL> call xdb_configuration.setFTPport(nnnn)

    2 > /

    For HTTP:

    SQL> call xdb_configuration.setHTTPport(nnnn)2 > /

    In the above examples nnnn represents the target port number. 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 selectedport numbers should not be privileged port numbers (0-1023).

    After resetting the port numbers validate the new numbers have been accepted executing the following statement:

    SQL> select xdburitype(/sys/databaseSummary.xml).getXML()

    2 > from dual

    3 > /

  • 8/8/2019 Oracle XML Basic Demo

    8/116

    Oracle XML DB Basic Demonstration

    Page 8 of 116 January 31, 2003

    TNSLISTENER CONFIGURATIONDisplay the current status of the TNS Listener using the command lsnrctl status. Executing the command shouldgenerate output similar to the following:

    Fig II. Verifying Listener Configuration

    If the database is running on a remote machine, the command must be executed from a Windows Command Promptsession or telnet session attached to the remote machine.

    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.xmldocument.

    Manual inspection of the listener.ora file can also be used to verify the port number being used for Oracle NetServices. The listener.ora file is located in the directory /n et w ork /a d m in .

    If the TNS Listener is not running on default port of 1521, a LOCAL_LISTENER parameter must be added to theinit.ora file used to configure the database. This will ensure that the Oracle XML DB protocols connect to the correct

    TNS Listener. If the output from the lsnrctl status command does not include entries describing FTP and HTTPservices then the database has not registered with this listener. Verify that the Listener version is 9.2.0.1.0 or greater.

    If the database has not registered with the listener make check whether a Local Listener has been configured. If aLOCAL_LISTENER entry has been configured ensure that it references the correct listener.

    See Appendix I for details on how to add a local_listener entry to the init.ora file).

  • 8/8/2019 Oracle XML Basic Demo

    9/116

    Oracle XML DB Basic Demonstration

    Page 9 of 116 January 31, 2003

    VERIFY XMLDB PROTOCOL CONFIGURATION AND CONN ECTIVITYConfirm that there are no HTTP or FTP port conflicts with other database instances running on the same host. Ifmultiple database instances are running on a given server each must be configured with HTTP and FTP port numbersthat are unique to the server machine. A given listener can service HTTP and FTP requests for multiple databaseinstances. Multiple listeners can run on a given server.

    In order to ensure that the port number are unique execute the xdbConfiguration.sql script on each database instanceUse the xdb_configuration package to assign unique FTP and HTTP ports to each database instance. To disableHTTP and FTP Services for a given database instance set the port numbers to zero.

    Once all of the database instances have been configured with unique port numbers, use the lsnrctl status command tocheck that each database instance has been re-configured to service unique FTP and HTTP port numbers.

    VERIFY SQL*NET AND XMLDBCONFIGURATION Verify that the Oracle Net Services, FTP and HTTP protocols are configured as expected using the followingprocedure. The following example assumes that the TNS alias ORCL92 will establish a connection to the targetdatabase.

    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. Make a note of the hostname, HTTP port number and FTP port number.

    Fig III. Verifying Protocol Configuration from SQL*PLUS

  • 8/8/2019 Oracle XML Basic Demo

    10/116

    Oracle XML DB Basic Demonstration

    Page 10 of 116 January 31, 2003

    Verify the FTP configuration by connecting to the target database via FTP as shown below. Since the target FTPServer is not running on the default FTP port of 21, the open command has to be used to establish the connection toserver. The hostname and FTP port number used in the open command should be taken from databaseSummary.xmldocument that was accessed using SQL.

    Fig IV. Verifying Protocol Configuration from FTP

    If the FTP Protocol is configured correctly the databaseSummary.xml document returned by the FTP Server shouldbe identical to the one that was accessed via SQL.

    Verify the HTTP configuration using the browser as shown below. The hostname and HTTP port number specifiedin the address should be taken from databaseSummary.xml document that was accessed using SQL. The browser willprompt for a username and password. Enter the name and password of the database user that will be used whenrunning the demonstration.

    Fig V. Verifying Protocol Configuration from HTTP

    If the HTTP Protocol is configured correctly the databaseSummary.xml document returned by HTTP Server shouldbe identical to the one that was accessed via SQL.

  • 8/8/2019 Oracle XML Basic Demo

    11/116

    Oracle XML DB Basic Demonstration

    Page 11 of 116 January 31, 2003

    CON FIGURING TH E DEMON STRATION INSTALLATION Unzipping the installation file creates a folder called basicDemo. This folder contains a folder called install. The installfolder contains a file called install.vbs, which will install the demonstration.

    The install folder also contains a file called installParameters.xml which drives the installation process. This filecontains the set of arguments required to tailor the installation. 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:

    9.2.0.2.0 Demo

    c:\oracle\ora92

    SCOTT

    TIGER

    ORCL92

    1521

    LISTENER

    localhost

    8080

    2100

    Change the contents of the file to reflect your environment. Special attention should be taken to ensure that the valuesfor , , and are correct. Save the file.

    After editing the installationParameters.xml file, verify that the file still contains well formed XML by opening it inInternet Explorer.

    Close the Command Prompt session.

  • 8/8/2019 Oracle XML Basic Demo

    12/116

    Oracle XML DB Basic Demonstration

    Page 12 of 116 January 31, 2003

    COMPLETING TH E DEMON STRATION INSTALLATION Open a Windows Explorer session and navigate to the Install folder. Start the installation script by double-clickingthe install.vbs script. The script will prompt for confirmation before starting the configuration process:

    Click OK to configure the demo.

    Fig VI. Installation Dialogs

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

    Click OK to complete installation of the demonstration.At this point the demonstration is installed and ready to run. If any of the values supplied to the installation procedurewere incorrect the demonstration can be re-installed by editing installParameters.xml file and then re-executing theinstall.vbsscript.

  • 8/8/2019 Oracle XML Basic Demo

    13/116

    Oracle XML DB Basic Demonstration

    Page 13 of 116 January 31, 2003

    WH AT IS TH E ORACLE XMLDATABASE?

    Oracle XML DB is the term used to describe technology in the Oracle 9i Release 2 database that delivers high-performance storage and retrieval of XML. This technology extends the popular Oracle relational database, delivering

    all of the functionality associated with a native XML database, in addition to all of the functionality provided by themost sophisticated and complete relational database currently available.

    Oracle XML DB provides a storage-independent, content-independent and programming-language-independentinfrastructure to store and manage XML data. It delivers new methods for navigating and querying XML contentstored inside the database and introduces an XML Repository for managing XML document hierarchies. With OracleXML DB, you get all the advantages of relational database technology and XML technology at the same time.

    Oracle XML DB delivers the following functionality:

    A native XML data-type that is used to store and manage XML documents.

    A set of methods and SQL operators which allow XML operations to be performed onXML content.

    The ability to absorb a standard W3C XML Schema data model into the Oracle database.

    XML/ SQL duality, allowing XML operations on SQL data and SQL operations on XML content.

    Industry-standard methods for accessing and updating XML, including XPath and SQL/ XML.

    An simple, light-weight XML Repository that allows XML content to be organized and managed using a file /folder / URL metaphor.

    Native database support for industry-standard, content-orientated, protocols including FTP, HTTP andWebDAV making it possible to move XML content in and out of the Oracle database.

    Multiple, industry-standard APIs that allow programmatic access and update of XML content from Java, C andPL/ SQL.

    XML-specific memory management and optimizations.

    The ability to bring the enterprise class management capabilities of the Oracle database, -- reliability, availability,scalability and unbreakable security -- to bear on XML content.

    Oracle XML DB

    extends the Oracle

    relational database,

    adding all of the

    nctionally associatedwith native XML

    databases

  • 8/8/2019 Oracle XML Basic Demo

    14/116

    Oracle XML DB Basic Demonstration

    Page 14 of 116 January 31, 2003

    ORACLE XMLDBMAJOR FEATURESAny database that is going to be used manage XML must be capable of more than simply persisting XML documents.It must provide standard database features like transaction control, data integrity, replication, reliability, availability,security and scalability. It must also provide the features required to efficiently index, query, update and search XMLcontent in an XML centric manner.

    One of the major challenges with using a traditional relational database to manage XML content is the hierarchicalnature of the XML world. Examples of this include

    Uniquely identifying an XML document: The standard way of identifying an XML document is via a URL.

    Defining relationships between XML documents: The standard way of defining a relationship between twodocuments is via URL based standards like XLink.

    Accessing and updating the content of an XML document. The standard ways of addressing and updatingcontent is via WC3 standards like XPath.

    URLs and XPath expressions are both intrinsically hierarchical in nature. A URL uses a path through a folderhierarchy to identify a document. The XPath standard uses a path through the XML documents node hierarchy toidentify or access the contents of part of an XML document.

    On the fact of it these hierarchical metaphors are not easy to map in the relational model. With a relational databasethe table-row metaphor is used to locate content. Primary-Key Foreign-Key relationships are used to define therelationships between content. 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 directsupport for the hierarchical nature of XML. These operators allow XML centric metaphors, such as XPathexpressions and URLs, to be used to query and update XML documents that are stored in an Oracle database.

    Here are the major features of Oracle XML DB:

  • 8/8/2019 Oracle XML Basic Demo

    15/116

    Oracle XML DB Basic Demonstration

    Page 15 of 116 January 31, 2003

    XMLTYPE XMLType is a native server data-type that allows the database to understand that a column or table contains XML; inthe same way that the DATE data-type allows the database to understand that a column contains a date. XMLTypealso provide methods that allow common operations such as schema validation and XSL Transformations to beperformed on XML content.

    The XMLType data-type can be used just like any other data-type. It can be used when creating a column in arelational table. It can be used when declaring PL/ SQL variables, and when defining and calling PL/ SQL proceduresand functions. Since XMLType is an object type, it is also possible to create a table of XMLType.

    The XMLType data type can also be used when defining views. Creating an XMLType view, or a relational view thatincludes an XMLType column, allows Oracle XML DB to be used to expose content stored relational tables andexternal data sources as XML documents.

    By default, an XMLType table or column can contain any well formed XML document. The content of the documentis stored as XML text using the CLOB data type. This allows for maximum flexibility in terms of the shape of theXML structures that can be stored in a single table or column and the highest rates of ingestion and retrieval.

    An XMLType table or column can be constrained to an XML Schema. Constraining a column or table to an XMLSchema 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 thecolumn or table.

    Since the contents of the table or column are conformant with a known XML structure, Oracle XML DB can usethe information contained in the XML Schema to provide more intelligent query and update processing of theXML.

    Constraining the XMLType to an XML Schema provides the option of storing the content of the document usingstructured-storage techniques. Structured-storage decomposes or shreds the content of the XML document andstores it as a set of SQL objects rather than simply storing the document as text in CLOB. The object-model usedto store the document is automatically derived from the contents of the XML Schema.

  • 8/8/2019 Oracle XML Basic Demo

    16/116

    Oracle XML DB Basic Demonstration

    Page 16 of 116 January 31, 2003

    The following diagram shows how XML can be stored and retrieved using Oracle XML DB and the XMLType datatype:

    Fig I. X M L T ype storage options

    The XMLType data-type provides constructors that allow an XMLType to be created from a VARCHAR or CLOBdata-type. It also provides a number of XML specific methods which can operate on XMLType objects. The methodsprovided by XMLType provide support for common operations like extracting a subset of the nodes contained in theXMLType ( extract()), checking whether or not a particular node exists in the XMLType (existsNode() ), validatingthe contents of the XMLType against an XML Schema ( schemaValidate() ), and performing an XSL Transformation( transform()).

    XML can be stored

    one of two ways:

    An XMLTypecolumn in a

    relational table.

    An XML object in

    an XMLType table.

    Non Schema based

    XML is always

    stored as CLOB.

    Schema based

    XML can be stored

    as a CLOB or as a

    set of objects.

    Relational and

    external data can

    be exposed as XML

    using views.

    The view can be a

    relational view

    containing a

    column of

    XMLType or can

    be a XMLType

    View.

    CLOBStorage

    Non Schema|

    Based XML

    SchemaBased XML

    TTaabbllee

    RelationalTables

    SchemaBased XML

    Non SchemaBased XML

    ExternalData

    Sources

    VViieeww

    ObjectRelationalStorage

    XXMMLL SScchheemmaa

  • 8/8/2019 Oracle XML Basic Demo

    17/116

    Oracle XML DB Basic Demonstration

    Page 17 of 116 January 31, 2003

    The following screen shot shows creating a simple table with an XMLType column and then performing insert andquery options against the table.

    Fig II. creating a relational table with a column of X M L T ype

    The XMLType

    data type can be

    used just like any

    other data type.

    The constructors of

    the XMLType

    allow XMLType to

    be created from

    VARCHAR and

    CLOB.

    Inserting into a

    table with an

    XMLType column

    is like inserting into

    any other table.

    New SQL

    operators make it

    possible to perform

    SQL queries over

    XML content.

  • 8/8/2019 Oracle XML Basic Demo

    18/116

    Oracle XML DB Basic Demonstration

    Page 18 of 116 January 31, 2003

    XMLSCHEMAComprehensive support for the W3C XML Schema standard is one of the key features of Oracle XML DB. XMLSchema is a W3C standard for specifying the structure, content, and certain semantics of a set of XML documents.The XML Schema standard is described by the W3C in http:/ / www.w3.org/ TR/ xmlschema-0/. Since an XMLSchema is used to define a class of XML documents, the term instance document is often used to describe an XMLdocument that conforms to a particular XML Schema.

    The W3C Schema Working Group publishes an XML Schema, often referred to as the Schema for Schemas. ThisXML Schema provides the definition, or vocabulary, of the XML Schema language. An XML Schema is an XMLdocument, which is compliant with the vocabulary defined by the Schema for Schemas. An XML Schema documentuses the vocabulary defined by W3C XML Schema Working Group to create a collection of type definitions andelement declarations which declare a shared vocabulary that describe the contents and structure of a new class ofXML documents.

    The XML Schema language defines 47 scalar data types. This provides for strong typing of the elements andattributes. The XML Schema standard also supports the use of object-oriented techniques like inheritance andextension, making is possible for the schema designer to create complex objects from the base data types defined bythe XML Schema language. The W3C XML Schema vocabulary also includes constructs that can be used to defineordering, default values, mandatory content, nesting, repeated sets, etc. Oracle XML DB supports all of constructs

    defined by the XML Schema standard, except for redefines.

    The most common usage of an XML Schema is as a mechanism for validating that an instance documents areconformant with a given XML Schema. The XMLType data type provides the methods isSchemaValid() andschemaValidate() that allow Oracle XML to use an XML Schema in this manner.

    N AMESPACES

    It is possible for two different XML Schemas to use the same name when defining an object (element, attribute,complex type, simple type, etc). Since the two objects are in different XML Schemas they cannot be treated as beingthe same item. This means that an instance document must identify which XML Schema a particular node is based on.The XML Namespace specification defines a mechanism which accomplishes this. An XML namespace is a collectionof names, identified by a URI reference which are used in XML documents as element types and attribute names.

    XMLSCHEMA AND N AMESPACES

    The targetNamespace attribute is used to define the namespace associated with a given XML Schema. The attribute isincluded in the definition of the schema element. If an XML Schema specifies a targetNamespace, all elements andtypes defined by the schema are associated with this namespace. This implies that any XML document that containsthese elements and types must identify which namespace the elements and types are associated with. If the XMLSchema does not specify a targetNamespace, all elements and types defined by the schema are associated with theNULL namespace.

    The XML Schema standard also defines a mechanism that allows an instance document to identify which XMLSchemas are required in order to process or validate the document. The XML Schemas in question are identified on anamespace by namespace basis using attributes defined in the WC3 XMLSchema-Instance namespace.

    In order to use this mechanism the instance document must first declare the XMLSchema-instance namespace. TheXMLSchema-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.w3.org/2001/XMLSchema-instance"

    Once the XMLSchema-instance namespace has been declared the required set of XML Schemas is defined by addingschemaLocation and noNamespaceSchemaLocation attributes to the root element of the document.

  • 8/8/2019 Oracle XML Basic Demo

    19/116

    Oracle XML DB Basic Demonstration

    Page 19 of 116 January 31, 2003

    The schemaLocation attribute is used to identify XML Schemas that included a targetNamespace declaration. TheschemaLocation attribute contains of one entry for each XML Schema. Each entry consists of a pair of values. The lefthand side of each pair is the value of the targetNamespace attribute. The right hand side of each pair is a hint, typicallyin the form of a URL, which describes where to find to the appropriate XML Schema. This hint is often referred to asthe Document Location Hint

    The noNamespaceSchemaLocationattribute is used to identify any XML Schema that did include a targetNamespacedeclaration. There can only be such XMLSchema for a given instance document. The noNamespaceSchemaLocationattribute contains a hint, typically in the form of a URL, which describe where to find the required XML Schema.

    REGISTERING AN XMLSCHEMABefore Oracle XML DB can make use of the information contained in an XML Schema, the XML Schema must beregistered with the database. An XML Schema is registered by called the PL/ SQL procedure calleddbms_xmlschema.register_schema(). The XML Schema is registered under a URL. The URL a used internally as aunique key used to identify the XML Schema. At no point does Oracle XML DB require direct access to the URLspecified when registering the XML Schema.

    When an XML Schema is registered with the database, a default table is created for each global element defined by theXML Schema. When an instance document is loaded in the Oracle XML DB repository, the content of the documentwill be stored in the default table. The default tables created by registering an XML Schema are XMLType tables, i.e.

    they are Object Tables, where each row in the table is represented as an instance of the XMLType data type.

    Oracle XML DB can use the information contained in an XML Schema to derive an object model that allows XMLcontent that is compliant with the XML Schema to be decomposed and stored in the database as a set of objects. Theconstructs defined by the XML Schema are mapped directly into SQL Types generated using the SQL 1999 TypeFramework that is part of the Oracle database.

  • 8/8/2019 Oracle XML Basic Demo

    20/116

    Oracle XML DB Basic Demonstration

    Page 20 of 116 January 31, 2003

    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.

    It can lead to significant reductions in the amount of space required to store the document.

    It can reduce the amount of memory required to query and update XML content.

    Capturing the XML Schema objects as SQL Types helps share the abstractions across schemas, and also acrosstheir SQL storage counterparts.

    It allows Oracle XML to support constructs defined by the XML Schema standard that do not easily map directlyinto the conventional relational model.

    DOMFIDELITY

    Using SQL 1999 objects to persist XML allows Oracle XML DB to guarantee DOM fidelity. DOM, or the DocumentObject Model, is a W3C standard that defines a set of platform- and language-neutral interfaces that allow a programto dynamically access and update the content, structure and style of a document. In order to provide DOM fidelityOracle XML DB must ensure that a DOM generated from a document that has been shredded and stored in OracleXML DB will be identical to a DOM generated from the original document.

    Providing DOM Fidelity requires Oracle XML DB to preserve all of the information contained in an XML document.This includes maintaining the order in which elements appear within a collection and within a document as well asstoring and retrieving out-of-band data like comments, processing instructions and mixed text. By guaranteeing DOMfidelity, Oracle XML DB is able to ensure that there is no loss of information when the database is used to store andmanage XML documents.

    ANN OTATING AN XMLSCHEMAOracle XML DB provides the application developer or database administrator with control over how muchdecomposition, or shredding, takes place when an XML document is stored in the database. The XML Schemastandard allows vendors to define schema annotations that add directives for specific schema processors. The OracleXML DB schema processor recognizes a set of annotations that make it possible to customize the mapping betweenthe XML Schema data types and the SQL data types, control how collections are stored in the database, and specifyhow much of a document should be shredded.

    If you do not specify any annotations to your XML Schema to customize the mapping, Oracle XML DB will makecertain default choices that may or may not be optimal for your application.

    IDEN TIFYING AND PROCESSING INSTANCE DOCUMENTS

    Oracle XML DB assumes that instance documents will use the W3C approved mechanism for identifying which XMLSchemas they are associated with. It assumes that the Document Location Hint contained in an instance documentwill map directly to the URL that was specified when registering the associated XML Schema with the database.

    For example, assume an XML Schema defines a global element PurchaseOrder. The XML Schema does not include atargetNamespace declaration. The XML Schema has been registered under the URLhttp://xmlns.oracle.com/demo/purchaseOrder.xsd. In order for an XML document to be recognized as an instance ofthe XML Schema the root element of an instance document would need to look like

  • 8/8/2019 Oracle XML Basic Demo

    21/116

    Oracle XML DB Basic Demonstration

    Page 21 of 116 January 31, 2003

    STRUCTURED VS UNSTRUCTURED STORAGE One of the key decisions to be made when using Oracle XML DB is persist XML documents is when to usestructured-storage and when to use unstructured storage.

    Unstructured-storage provides for the highest possible throughput when inserting and retrieving entire XMLdocuments. 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. These throughput and flexibility benefits come at the expense of certain aspects ofintelligent processing. There is little that the database can do to optimize queries or updates on XML that has beenstored using a CLOB data type.

    Structured-storage provides a number of advantages for managing XML, including optimized memory management,reduced storage requirements, b-tree indexing and in-place updates. These advantages are at a cost of somewhatincreased processing overhead during ingestion and retrieval and reduced flexibility in terms of the structure of theXML that can be managed by a given XMLType table or column.

    The relevant merits of Structured and Unstructured storage are outlined in the following table

    Unstructured Storage Structured Storage

    Throughput Highest possible throughputwhen ingesting and retrievingthe entire content of an XMLdocument.

    The decomposition process results inslightly reduced throughput wheningesting or retrieving the entire contentof an XML document.

    Flexibility Provides the maximumamount of flexibility in termsof the structure of the XMLdocuments that can be storedin an XMLType column ortable.

    Limited Flexibility. Only document thatconform to the XML Schema can bestored in the XMLType table or column.Changes to the XML Schema mayrequire data to be unloaded and re-loaded

    XML

    Fidelity

    Delivers Document Fidelity:

    Maintains the original XMLbyte for byte, which may beimportant to someapplications

    DOM Fidelity: A DOM created from an

    XML document that has been stored inthe database will be identical to a DOMcreated from the original document.However trailing new lines, white spacecharacters between tags and some dataformatting may be lost

    OptimizedUpdateOperations

    Optimized update operationare not possible. When anypart of the document isupdated the entire documentmust be written back to disk.

    The majority of update operations canbe optimized using Query re-write. Thisallows in-place, piece-wise update,leading to significantly reduced responsetimes and greater throughput.

    XPath based

    queries.

    XPath operations evaluated

    by constructing DOM fromCLOB and using functionalevaluations. This can be veryexpensive when performingoperations on largecollections of documents.

    Where possible, XPath operations are

    evaluated using query-rewrite, leading tosignificantly improved performance,particularly with large collections ofdocuments.

    SQLConstraintSupport

    SQL constraints are notcurrently available.

    SQL constraints are supported.

  • 8/8/2019 Oracle XML Basic Demo

    22/116

    Oracle XML DB Basic Demonstration

    Page 22 of 116 January 31, 2003

    IndexingSupport

    Text and Functional indexes. B-Tree, Text and Functional Indexes.

    OptimizedMemoryManagement

    XML operations of thedocument require creating aDOM from the document

    XML operations can be optimized toreduce memory requirements.

    Table 1: Pros and cons of XML storage options

  • 8/8/2019 Oracle XML Basic Demo

    23/116

    Oracle XML DB Basic Demonstration

    Page 23 of 116 January 31, 2003

    XML/SQLDUALITYMuch of the valuable information within an organization is in the form of semi-structured and unstructured data.Typically this data is contained in files stored on a file server or in a CLOB column inside a database. The informationin these files is in proprietary or application specific formats. It can only be accessed via specialist tools, such as wordprocessors or spreadsheets, or programmatically using complex, proprietary APIs. Searching across this information islimited to the facilities provided by a crawler or full text indexing.

    One of the major drivers behind the rapid adoption of XML is that it allows for stronger management and more openaccess to semi-structured and unstructured content. Replacing proprietary file formats with XML allows organizationsto achieve much higher levels of reuse of their semi-structured and unstructured data. The content can be accuratelydescribed using XML Schema. The content can be easily accessed and updated using standard APIs based on DOMand XPath.

    For instance, information contained in an Excel spreadsheet is only accessible to the Excel program, or to a programthat uses Microsofts COM APIs. The same information, stored in an XML document is accessible to any tool thatcan leverage the XML programming model.

    Structured data on the other hand does not suffer from these limitations. Structured data is typically stored as rows intables within a relational database. These tables are accessed and searched using the relational model and the powerand openness of SQL from a variety of tools and processing engines.

    By delivering on the promise of XML SQL duality, Oracle XML DB erases the traditional boundary betweenapplications that work structured data and those that work with semi-structured and unstructured content. WithOracle XML DB the relational and XML metaphors become interchangeable. XML/ SQL duality means that the samedata can be exposed as rows in a table and manipulated using SQL or exposed as nodes in an XML document andmanipulated using techniques like DOM or XSL transformation. The access metaphor and processing techniquesused are totally independent of the underlying storage format.

    This means that the XML programmer can leverage the power of the relational model when working with XMLcontent and the SQL programmer can leverage the flexibility of XML when working with relational content. Thisprovides application developers with maximum flexibility, allowing them to use the most appropriate tools to solvinga particular business problem.

    This means that Oracle XML DB is able to provide new, simple solutions to a number of common businessproblems.

    Relational data can quickly and easily be converted into HTML pages. Oracle XML DB provides new SQLoperators that make it possible to generate XML directly from a SQL query. The XML can be transformed intoother formats, such as HTML using the database-resident XSLT processor.

    Organizations can easily leverage all of the information contained in their XML documents without having toincur the overhead of converting back and forth between different formats. Oracle XML DB makes it possible toaccess XML content using SQL queries, On-line Analytical Processing (OLAP) and Business-Intelligence/ DataWarehousing operations.

    Text, Spatial Data, and Multimedia operations can be performed on XML Content.

    SQL/ XMLOracle XML DB also provides an implementation of the majority of the operators that will be incorporated into theforthcoming SQL/ XML standard. SQL/ XML is defined by specifications prepared by the International Committeefor Information Technology Standards (Technical Committee H2), which is the main standards body for developingstandards for the syntax and semantics of database languages, including SQL. See http:/ / sqlx.org andhttp:/ / www.ncits.org/ tc_home/ h2.htm for more information.)

    The SQL/ XML operators fall into two categories. The first category consists of a set of operators that make itpossible to query and access XML content as part of normal SQL operations. The second category consists of a set ofoperators that provide an industry standard method for generating XML from the result of a SQL Select statement.

  • 8/8/2019 Oracle XML Basic Demo

    24/116

    Oracle XML DB Basic Demonstration

    Page 24 of 116 January 31, 2003

    The SQL/ XML operators make it possible to address XML content in any part of a SQL Statement. The SQL/ XMLoperators use XPath notation is used to traverse the XML structure and identify the node or nodes on which tooperate. XPath is a popular syntax (see http:/ / www.w3.org/ TR/ xpath) familiar to both programmer and content-creators, and the ability to embed XPath expressions within SQL statements greatly simplifies XML access.

    The existsnode() operator is used in the where clause of a SQL statement to restrict the set of documents returned bya query. The existsnode() operator takes an XPath expression and expression and applies it an XML document. Theoperator and returns true (1) or false (0) depending on whether or not the document contains a node which matchesthe XPath expression.

    The extract() operator takes an XPath expression and returns the node or nodes that matches the expression as anXML document or fragment. If a single node matches the XPath expression the result will be a well-formed XMLdocument. If multiple nodes match the XPath expression the result will be a document fragment.

    The extractvalue()operator takes an XPath expression and returns the corresponding leaf level node. The XPathexpression passed to extractvalue() should identify a single attribute, or an element which has precisely one text nodechild. The result is returned in the appropriate SQL data type.

    The updatexml()operator allows partial updates to be made to an XML document, based on a set of XPathexpressions. Each XPath expression identifies a target node in the document, and a new value for that node. Theupdatexml() operator allows multiple updates to be specified for a single XML document.

    The xmlsequence() operator makes it possible to expose the members of a collection as a virtual table.

    Detailed examples of the way in which these functions are used are provided in the PurchaseOrder example.

  • 8/8/2019 Oracle XML Basic Demo

    25/116

    Oracle XML DB Basic Demonstration

    Page 25 of 116 January 31, 2003

    XPATH AN D QUERY RE-WRITEThe SQL/ XML operators, and the corresponding XMLType methods, allow XPath expressions to be used to searchcollections of XML documents and to access a subset of the nodes contained within an XML document. Oracle XMLDB has two methods of evaluating XPath expressions that operate on XMLType columns and tables.

    For XML that has been stored using structured storage techniques, Oracle XML DB will attempt to translate

    the XPath expression in a SQL/ XML operator into an equivalent SQL query. The SQL query references theObject-Relational data structures that underpin a schema-based XMLType. While this process is referred toas Query-rewrite, it can also occur when performing update operations.

    For XML that has been stored using unstructured storage, Oracle XML DB will evaluate the XPath usingfunctional evaluation. Functional evaluation builds a DOM tree for each XML document and then resolvesthe XPath programmatically using the methods provided by the DOM API. If the operation involvesupdating the DOM tree, the entire XML document has to be written back to disc when the operation iscompleted.

    Query-rewrite makes it possible for the database to efficiently process SQL statements containing one or more XPathexpressions using conventional relational SQL. By translating the XPath expression into a conventional SQLstatement, Oracle XML DB insulates the database optimizer from having to understand XPath notation and the XMLdata model. The database optimizer simply processes the re-written SQL statement in the same manner as it would

    any other SQL statement.

    This means that the database optimizer is able derive an execution plan based on conventional relational algebra. Thisallows Oracle XML DB to leverage all of the features of the database and ensure that SQL Statements containingXPath expressions are executed in a highly performant and efficient manner. There is very little overhead associatedwith the process of Query-rewrite, and this means that Query-rewrite allows Oracle XML DB to execute XPath basedqueries at near-relational speed while still preserving the XML abstraction.

    Query-rewrite is possible in the following circumstances.

    The SQL statement contains SQL/ XML operators or XMLType methods that use XPath expressions to refer toone or more nodes within a set of XML documents.

    The XMLType column or table containing the XML documents is associated with a registered XML Schema.

    The XMLType column or table uses structured storage techniques to provide the underlying storage model.

    The nodes referenced by the XPath expression can be mapped, via the XML Schema, to attributes of theunderlying SQL object model.

    The Query-rewrite process is as follows:

    Identify the set of XPath expressions included in the SQL statement.

    Translate each XPath expression into an Object Relational SQL expression that references the tables, types andattributes of the underlying SQL: 1999 object model.

    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.In certain cases Query-rewrite is not possible. This can occur when there is no SQL equivalent for a particular XPathexpression. In this situation Oracle XML DB will create a DOM and then use the DOM to perform a functionalevaluation of the XPath expressions.

  • 8/8/2019 Oracle XML Basic Demo

    26/116

    Oracle XML DB Basic Demonstration

    Page 26 of 116 January 31, 2003

    In general, functional evaluation of a SQL statement will be much more expensive than Query-rewrite, particularly ifthe number of documents that needs to be processed is large. However the advantage of functional evaluation is thatit is can be used to evaluate any XPath expression, regardless of whether or not the XMLType is stored usingstructured storage and regardless of the expressions complexity. When documents are stored using unstructuredstorage (in a CLOB), functional evaluation will be necessary any time the extract(), extractvalue() , updatexml()operators are used. 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, and the conditions under which query re-write can take place, is one ofthe key steps in developing Oracle XML DB applications that will deliver the required levels of scalability andperformance

  • 8/8/2019 Oracle XML Basic Demo

    27/116

    Oracle XML DB Basic Demonstration

    Page 27 of 116 January 31, 2003

    XMLDBREPOSITORYThe relational model, with its powerful table-row-column metaphor, is widely accepted as the most effectivemechanism for managing structured data. The relational metaphor is not so effective when it comes to managingsemi-structured and unstructured data, such as document- or content-orientated XML. A book does not easily lend itself to being represented as a set of rows in a table. It is more natural to represent a book as a hierarchy, book chapter section paragraph, and to represent the hierarchy as a set of folders and subfolders.

    Relational databases are traditionally considered to be poor at managing hierarchical structures and performing thekind hierarchical traversal operations that are required to resolve a path. In order to resolve this problem, Oracle XMLDB introduces the concept of a query-able, hierarchically organized XML Repository. The Oracle XML DBrepository allows the hierarchical metaphor to be used to manage document-centric XML content. Using therepository, it is possible to represent XML content as documents in a folder hierarchy, and use hierarchicalmetaphors, such as paths and URLs, to access documents and represent the relationships between documents.

    Oracle XML DB includes a new, patented hierarchical index which speeds up folder- and path-traversals with-in theOracle XML DB Repository. The hierarchical index is totally transparent to the end-user, and allows Oracle XML DBto perform folder and path traversals at speeds that are comparable to or faster than conventional file-systems.

    One of the major advantages of the Oracle XML DB repository is that it allows content authors and editors to workdirectly with XML content stored in the database. The majority of the tools used to author XML are now able toaccess content using internet protocols like HTPP, FTP and WebDAV. Oracle XML DB adds native support forthese popular protocols to the database, allowing authors and editors direct access to content managed by the OracleXML DB repository. Oracle XML DB also provides the application programmer with direct access to the repositoryfrom both SQL and PL/ SQL. This makes it possible to develop applications which access and update contentmanaged by the Oracle XML DB repository.

    The WebDAV protocol is an IETF standard that defines a set of extensions to HTTP that allow an HTTP Server toact as a file server for a DAV enabled client. The WebDAV standard uses the term resource to describe a file or afolder. Every resource managed by a WebDAV server is identified by a URL. This terminology is adopted by theOracle XML DB repository.

    Since the HTTP, FTP and WebDAV protocols were designed with document-centric operations in mind, they aretypically more efficient than Oracle NET for manipulating large volumes of content. By providing support for these

    protocols at the database level Oracle XML DB allows Windows Explorer, Microsoft Office and products fromvendors like Altova, Macromedia and Adobe to work directly with XML content stored in the Oracle XMLDB repository.

    The following screen shot shows the root level directory of the Oracle XML DB repository as seen from Microsofts

    Windows Explorer.

    Fig III. M icrosoft W eb Folders view of Oracle X M L D B repository.

  • 8/8/2019 Oracle XML Basic Demo

    28/116

    Oracle XML DB Basic Demonstration

    Page 28 of 116 January 31, 2003

    As can be seen, WebDAV clients, such as Microsofts Windows Explorer, can connect directly to the XML DBrepository. No additional Oracle or Microsoft specific software or other complex middleware needs to be installed inorder to enable this functionality. This means that end users can work directly with the Oracle XML DB Repositoryusing the tools and interfaces that they are already familiar with.

    Each document in the Oracle XML DB is secured with an Access Control List. An Access Control List (ACL) is anXML document that contains a set of Access Control Entries (ACE). Each ACE grants or revokes a set ofpermissions to a particular user or group (database role). This access control mechanism is based on the WebDAVspecification. The repository also provides support for basic versioning based on the WebDAV standard.

    Another benefit of the XML DB Repository is that it is query-able from SQL. Content stored in the Oracle XML DBrepository can be accessed and updated from SQL and PL/ SQL. It is possible to interrogate the structure of therepository in complex ways (how many documents with a .xsl extension are under a location other than

    /h om e /m ys ty lesh ee td i r ?). It is also possible to mix path-based repository access with content-based access tothe documents (how many documents not under / home/ purchaseOrders have a node named/Purch a se Order /User / tex t () 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 thedatabase user XDB. This user is created as part of the Oracle XML DB installation procedure. The primary table inthis schema is an XMLType table called XDB$RESOURCE. The table contains one row for each file or folder

    managed by the Oracle XML DB repository. The documents in this table are referred to as resource documents.

    The XDB$RESOURCE table is not directly exposed to the SQL programmer. Instead the contents of the repositoryare exposed via two public views, the RESOURCE_VIEW and the PATH_VIEW. The RESOURCE_VIEW andPATH_VIEW provide the SQL programmer the ability to access and update both the meta-data and content of adocument stored in the Oracle XML DB repository.

    Both the RESOURCE_VIEW and the PATH_VIEW contain a column called RES.This is an XMLType column thatcan be used to access and update the resource asscociated with a document stored in the Oracle XML DB repository.These views also make it possible to create SQL statements which access and update resource documents based on apath notation. Operations on these views translate into operations on the underlying tables in the Oracle XML DBrepository.

    Oracle XML DB includes two new repository specific SQL operators: exists_path() and under_path(). These

    operators make it possible to include path based predicates in the where clause of a SQL statement. This means thatSQL operations can select repository content based on the location of the content within the folder hierarchy. TheHierarchical Index ensures that path-based queries are executed very efficiently.

    When Schema Based XML documents are stored in the Oracle XML DB repository the document content is storedas an object in the default table identified by the XML Schema. The repository contains the meta-data about thedocument and a pointer (REF of XMLTYPE) that identifies the row in the default table that contains the content.

    It is also possible to store other kinds of documents in the repository. When non-xml and non-schema based XMLdocuments are stored in the repository, the content of the document is stored in a LOB alongside the meta-data aboutthe document

    Since the Oracle XML DBrepository can be accessed and updated using SQL, any application capable of calling aPL/ SQL procedure can work with the Oracle XML DB repository. All SQL and PL/ SQL repository operations aretransactional, and access to the repository and its contents is subject to database security as well as XML DBRepository Access Control Lists (ACLs). When repository content is accessed via SQL ACL based security isenforced via Row Level security.

    The supplied PL/ SQL packages DBMS_XDB, DBMS_XDBZ and DBMS_XDB_VERSION provide the SQLprogrammer the ability to perform common tasks on the repository itself. The methods provided by these packagesmake it possible to create, delete and rename documents and folders, to move a file or folder within the folderhierarchy, to set and change the access permissions on a file or folder and the ability to initiate and manage versioning.

  • 8/8/2019 Oracle XML Basic Demo

    29/116

    Oracle XML DB Basic Demonstration

    Page 29 of 116 January 31, 2003

    The following diagram show the overall architecture of the Oracle XML DB repository

    Fig IV .Oracle X M L D B repository architecture overview

    QL and non SQL

    lients access the

    epository using the

    Oracle Net ServicesListener

    QL clients access

    he repository via

    he PATH_VIEW

    nd

    RESOURCE_VIEW

    r the DBMS_XDB

    PL/SQL package

    Non-SQL clients

    ccess content via

    he Oracle XML DBrotocol servers.

    The protocol servers

    re Oracle MTS

    rocesses

    All meta-data is

    managed by the

    Oracle XML DB

    epository.

    All content, other

    han schema-based

    XML is stored in theepository.

    The content of

    chema-based XML

    ocuments is stored

    n the default table

    efined by the

    chema.

    The Hierarchical

    ndex enables high

    peed lookup based

    n a path

    QL clients can

    ccess schema-based

    XML directly or via

    he repository

    DBMS_XDBPL/SQL

    Package

    Resource Viewand

    Path View

    Meta Data(DAV Resource)

    NonXML Content(LOB column)

    Non Schema-BasedXML Content(LOB column)

    Schema BasedXML Content

    (XMLType Table or View)

    SQL ClientWebDAVor FTPClient

    HTTP

    Client

    HTTP, FTP andWebDAV Protocol

    Servers

    Oracle Net Services Listener

    Hierarchical

    Index

    XXMMLL DDBB RReeppoossiittoorryy

  • 8/8/2019 Oracle XML Basic Demo

    30/116

    Oracle XML DB Basic Demonstration

    Page 30 of 116 January 31, 2003

    The following screen shot shows the PL/ SQL package DBMS_XDB being used to create a set of subfolders beneaththe folder/home/SCOTT.

    Fig V . Using PL / SQ L to update Oracle X M L D B R epository

    Note that as a consequence of the transactional semantics enforced by the database, folders created using SQLstatements will not be visible to other database users until the transaction is committed. Concurrent access to theOracle XML DB repository is controlled by the same mechanism as is used to control concurrency in the database.The integration of the repository with the database brings the benefits of strong management to XML content.

    One common problem encountered when using a relational database to maintain hierarchical folder structures is theproblem of ensuring a high degree of concurrency when adding and removing items in a folder. In conventional filesystem there is no concept of a transaction. Each operation (add a file, create a subfolder, rename a file, delete a file,etc.) is treated as an atomic transaction. Once the operation has completed the change is immediately available to allother users of the file system.

    As the above example shows, 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. This means that applications can create long-running transactions that include updates to one or more folders. In this situation a conventional locking strategy thattakes an exclusive lock on each updated folder or directory tree would quickly result in significant concurrencyproblems and performance degradation.

  • 8/8/2019 Oracle XML Basic Demo

    31/116

  • 8/8/2019 Oracle XML Basic Demo

    32/116

    Oracle XML DB Basic Demonstration

    Page 32 of 116 January 31, 2003

    PROGRAMMATIC ACCESSAll of the Oracle XML DB functionality is accessible from C, PL/ SQL and Java. Today, the most popular methodsfor building web-based applications are servlets/ JSPs (Java Server Pages) and XSL/ XSPs (XML Style sheets / XMLServer Pages). Typically, servlets and JSPs access data via JDBC, while XSL/ XSPs expect data in the form of XMLdocuments, which are processed via a DOM (Document Object Model) API implementation. Oracle XML DBsupports both styles of application development. Java and PL/ SQL implementations of the DOM API are provided.

    A C implementation is forthcoming.

    Applications that make use of JDBC, such as those based on servlets, need to have some advance knowledge of thestructure of the data they are going to process. The Oracle JDBC drivers allow application programmers to access andupdate XMLType tables and columns, and to call the PL/ SQL procedures that access the Oracle XML DBrepository.

    Applications that make use of DOM, such as those based on XSLT transformations; typically require less knowledgeof the data structure. A DOM based application uses string names to identify pieces of content, and must dynamicallywalk through the DOM tree to find the required information. Oracle XML DB allows application developers to usethe DOM API to access and update XMLType columns and tables. Programming to a DOM API is more flexiblethan programming via JDBC, but it may require more resources at run time.

  • 8/8/2019 Oracle XML Basic Demo

    33/116

    Oracle XML DB Basic Demonstration

    Page 33 of 116 January 31, 2003

    ORACLE XMLDB PERFORMANCEOne common objection to using XML to represent data is that it generates higher overhead than otherrepresentations. Oracle XML DB incorporates a number of features that are specifically designed to address this issueby significantly improving the performance of XML processing.

    XMLSTORAGE REQUIREMENTSSurveys have shown that data represented in XML and stored in a text file is three times the size of the same data in aJava object or in relational tables. There are two reasons for this. First, tag names (metadata describing the data) andwhite space (formatting characters) take up a significant amount of space in the document, particularly for highlystructured, data-centric XML. Secondly, all of the data in an XML file is represented in human readable (string)format. In the case of numeric data the string representation of a numeric value needs about twice as many bytes asthe native (binary) representation

    When XML documents are stored in Oracle XML DB using the structured storage option, the shredding processdiscards all of the tags and white space contained in the document. The amount of space saved by this optimizationdepends on the ratio of tag names to data, and the number of collections in the document. For highly-structured,data-centric XML the savings can be significant. When a document is printed, or when node-based operations such asXPath evaluations take place, Oracle XML DB uses the information contained in the associated XML Schema todynamically reconstruct any necessary tag information.

    XMLMEMORY MANAGEMENTThe Document Object Model (DOM) is the dominant programming model for XML documents. The DOM APIsare very easy to use but the DOM Tree that underpins them is expensive to generate, in terms of memory. A typicalDOM implementation maintains approx 80 120 bytes of system overhead for each node in the DOM tree. Thismeans that for highly structured data the DOM tree can require 10-20 times more memory than the document onwhich it is based.

    A conventional DOM implementation requires that the entire contents of an XML document be loaded into theDOM tree before any operations can take place. If an application only needs to process a small percentage of thenodes in the document this is extremely inefficient in terms of both memory and processing overhead. The alternativeSAX approach reduces the amount of memory required to process an XML document, but has the majordisadvantage that it only allows linear processing of the nodes contained in the XML Document.

    Oracle XML DB reduces the memory overhead associated with the DOM programming model by managing schema-based XML documents using an internal in-memory structure called a XML Object (XOB). A XOB is much smallerthan the equivalent DOM since it does not duplicate information like tag names and node types, which can easily beobtained from the associated XML Schema. Oracle XML DB will automatically use a XOB whenever an application isworking with the contents of a schema-based XMLType. The use of the XOB is transparent to the applicationdeveloper; it is hidden behind the XMLType data-type and the C, PL/ SQL and Java APIs.

    The XOB is also able to reduce the amount of memory required to work with an XML document via a feature calledthe Lazily-Loaded Virtual DOM. This feature allows Oracle XML DB to defer loading the in-memory representationof nodes that are part of sub-elements or collection until some methods attempt to operate on a node within thatobject. Consequently, if an application only operates on few nodes in a document, only those nodes and theirimmediate siblings will be loaded into memory.

    The XOB can only used in conjunction with a XML document that is based on an XML Schema. If the contents ofthe XML document are not based on an XML Schema, a traditional DOM will be used instead of the XOB..

  • 8/8/2019 Oracle XML Basic Demo

    34/116

    Oracle XML DB Basic Demonstration

    Page 34 of 116 January 31, 2003

    XMLPARSING OPTIMIZATIONSIn order to populate a DOM tree the application must parse the XML document. The process of creating a DOMtree from an XML file is very CPU- intensive. In a typical DOM based application, where the XML documents arestored as text, every document has to be parsed and loaded into the DOM tree before the application can work withit. If the contents of the DOM tree are updated the whole tree has to be serialized back into a text format and writtenout to disk.

    Oracle XML DB eliminates the need to keep re-parsing documents. Once an XML document has been stored usingstructured storage techniques no further parsing is required when the document is loaded from disk into memory.Oracle XML DB is able to map directly between the on-disk format and in-memory format using information derivedfrom the associated XML Schema. When changes are made to the contents of a schema-based XMLType, OracleXML DB is able to write just the updated data back to disk.

    Once again, when the contents of the XMLType are not based on an XML Schema a traditional DOM will be usedinstead.

    NODE SEARCHING OPTIMIZATIONSMost DOM implementations suffer from the fact that they use string comparisons when searching for a particularnode within the DOM tree. The means that performing even a simple search of a DOM tree can require hundreds or

    thousands of instruction cycles.Searching for a node in a XOB is much more efficient than searching for a node in a DOM. A XOB is based acomputed offset model (similar to a C/ C++ object) and it uses dynamic hash-tables rather than string comparisons toperform node searches.

    XMLSCHEMA OPTIMIZATIONSMaking use of the powerful features associated with XML Schema in a conventional XML application typicallygenerates significant amounts of additional overhead. For instance, before an XML document can be validated againstan XML Schema, the schema itself must be located, parsed and validated.

    Oracle XML DB minimizes the overhead associated with using XML Schema. When an XML Schema is registeredwith the database it is loaded in the Oracle XML DB Schema cache, along with all of the meta-data required to mapbetween the XML, XOB and on-disk representations of the data. This means that once the XML Schema has beenregistered with the database no additional parsing or validation of the XML Schema is required before it can be used.The schema cache is shared by all users of the database. Whenever an Oracle XML DB operation requiresinformation contained in the XML Schema it is able access the required information directly from the cache.

    LOAD BALANCINGSome operations, such as performing a full Schema validation, or serializing an XML document back into text formcan still require significant memory and CPU resources.

    Oracle XML DB allows these operations to be off-loaded to the client or mid tier processor. The OCI interface andthick JDBC driver both allow the XOB to be managed by the client. The cached representation of the XML Schemacan also be downloaded to the client. This allows operations like XML printing, and XML Schema validation toperformed using client or mid-tier resources, rather than server resources.

  • 8/8/2019 Oracle XML Basic Demo

    35/116

    Oracle XML DB Basic Demonstration

    Page 35 of 116 January 31, 2003

    NO N-NATIVE CODE Another bottleneck for XML-based Java applications is the cost associated with parsing an XML file. Even nativelycompiled or JIT compiled Java performs XML passing operations twice as slowly as native C implementations. Oneof the major performance bottlenecks in implementing XML applications is the cost of transforming the datacontained in an XML document between text, Java and the native server representations. The cost of performingthese transformations is proportional to the size and complexity of the XML file and becomes quite severe with even

    moderately sized files.

    Oracle XML DB addresses these issues by implementing all of the Java and PL/ SQL interfaces as very thin facadesover a native C implementation. This provides for language-neutral XML support (Java, C, PL/ SQL and SQL areall using the same underlying implementation), as well as for high performance XMP parsing and DOM processing.

    TYPE CONVERSIONSOne of the biggest bottlenecks in using Java in conjunction with XML is the cost of type conversions. Internally Javauses UCS-2 to represent all character data. Most XML files and databases do not contain UCS-2 encoded data. Thismeans that all the data contained in an XML file has to be converted from 8 Bit or UTF8 encoding into UCS-2encoding before it can be manipulated inside a Java program.

    XML DB addresses these problems with lazy type conversions. 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 thecontents of the node. Data remains in the internal representation until the last possible moment. Avoidingunnecessary type conversions can result in significant performance improvements in the cases where an applicationonly needs to access a few of the nodes contained in an XML document.

    Consider the case of a JSP that wants to load a name from the database and print it out in the generated HTMLoutput. Typical JSP implementations would read the name from the database (which probably contains data in theASCII or ISO8859 character sets) convert the data to UCS-2, and return it to Java as a String. The JSP wouldn't lookat the contents of the string, but merely print it out after printing the enclosing HTML, probably converting back tothe same ASCII or ISO8859 for the client browser. XML DB provides a write interface on XMLTYPE so that anyelement can write itself directly to a stream (such as a ServletOutputStream) without conversion through Javacharacter sets.

  • 8/8/2019 Oracle XML Basic Demo

    36/116

  • 8/8/2019 Oracle XML Basic Demo

    37/116

    Oracle XML DB Basic Demonstration

    Page 37 of 116 January 31, 2003

    PERFORMING TH E DEMON STRATION

    To start the demonstration, open the folder XML DB Basic Demo. Note that you can override the default name ofthis folder by specified in installParameters.xml. If the demo has been installed correctly this folder will be located onyour Desktop. When you open the folder you will see the following Icons.

    Fig VII. Demonstration Folder, showing ICONS used to run the Oracle XML DB basic demo

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

    this folder in turn

  • 8/8/2019 Oracle XML Basic Demo

    38/116

  • 8/8/2019 Oracle XML Basic Demo

    39/116

    Oracle XML DB Basic Demonstration

    Page 39 of 116 January 31, 2003

    1.0XMLDBREPOSITORYThis step demonstrates how the WebDAV protocol makes it possible to access the XML DB repository using theusing Windows Explorer..

    The Oracle XML DB repository allows a file / folder metaphor to be used to organize and manage XML, and otherkinds of content. Since the repository supports the HTTP, WebDAV and FTP protocols, it is possible to access

    content stored in the XML DB repository using standard tools like Windows Explorer and Microsoft Office. Noplug-ins, adaptors or drivers need to be installed in order for these tools to work with the Oracle XML DB repository.

    Click once on the shortcut 1.0 XML DB Reposi tory.

    This will launch Window Explorer and open a folder containing a shortcut called XML DB on hostname.

    Click on this shortcut .

    This will establish a WebDAV connection to the XML DB repository. You will be prompted for username andpassword.

    Enter the appropriate database user and password and click OK.

    The following window should be displayed:

    Fig VIII. Microsoft Web Folders view of Oracle XML DB repository

    Double-click on the h o m e folder icon.

    This folder will contain a folder named for demonstration user. In this example the demonstration is being run usingthe database user SCOTT so the folder is called SCOTT.

    Double-click on the demonstration users home folder.

  • 8/8/2019 Oracle XML Basic Demo

    40/116

    Oracle XML DB Basic Demonstration

    Page 40 of 116 January 31, 2003

    This will display an empty folder.

    Create a new folder by clicking the right mouse button and selecting N ew -> Folder.

    Fig IX. Using Windows Explorer to create a folder in the Oracle XML DB repository

    Give the new folder a clearly identifiable name.

    The home folder should now contain one sub-folder, with the name specified.

    Fig X. Home Folder with newly created sub-folder

  • 8/8/2019 Oracle XML Basic Demo

    41/116

    Oracle XML DB Basic Demonstration

    Page 41 of 116 January 31, 2003

    KEYPOINTS:

    Windows Explorer can connect directly to the XDB repository. No additional Oracle or Microsoft specificsoftware has to be installed in order to make this work. This means that end users can work with the Oracle XMLDB repository using the tools and interfaces that they are already familiar with.

    This connectivity is possible because Windows Explorer and Oracle XML DB both support open, internet

    standards, in this case the WebDAV protocol.

    Many vendors, including Microsoft, Adobe and Macromedia, are including support for WebDAV in their productsets. This means that applications such as Word, Excel, Acrobat and Dreamweaver are able to work directly withcontent stored and managed by Oracle XML DB.

    WebDAV is an IETF standard that defines a set of extensions to the HTTP protocol that allow an HTTP Serverto act as a file server for a DAV enabled client. The WebDAV standard uses the term resource to describe a fileor a folder. Every resource managed by a WebDAV server is identified by a URL.

    Do not close the WebDAV window at this point.

  • 8/8/2019 Oracle XML Basic Demo

    42/116

    Oracle XML DB Basic Demonstration

    Page 42 of 116 January 31, 2003

    1.1MAKE DIRECTORIESThis step demonstrates that the Oracle XML DB repository can be accessed and updated from SQL, as well as via theprotocols. It also shows that, when accessed via SQL, repository operations are transactional.

    Execute the SQL script by clicking on the Icon.

    Fig XI. Using PL/SQL to update Oracle XML DB Repository

    The script will result in a set of folders being created inside the folder/h om e/ S COTT.

    Do not continue the SQL*PLUSW session at this point.

    KEY POINT S :

    The Oracle XML DB repository SQL to be used to access and manipulate repository and well as standardprotocols such as WebDAV and FTP.

    The PL/ SQL package DBMS_XDB can be used to perform operations on the repository from SQL. This meansthat any program that can call a PL/ SQL procedure can work with the Oracle XML DB repository.

  • 8/8/2019 Oracle XML Basic Demo

    43/116

    Oracle XML DB Basic Demonstration

    Page 43 of 116 January 31, 2003

    Click on the window containing the WebDAV view of the demonstration users home folder. Refresh thecontents of this Window. Note that the folders that were created by executing the PL/ SQL script are NOTvisible, even after refreshing the display.

    Fig XII. Windows Explorer unable to see uncommitted changes to Oracle XML DB repository

    KEY POINT S :

    This is the expected behavior. PL/ SQL operations are transactional, and the transaction has not been committed.Consequently the changes made in the PL/ SQL session are not visible to other users.

  • 8/8/2019 Oracle XML Basic Demo

    44/116

    Oracle XML DB Basic Demonstration

    Page 44 of 116 January 31, 2003

    Click on the Window containing the