DBMS Support in Oracle 9i Release 2 Presentation Paper Marouane Bouzoubaa XML & Data Management Supervisor: Dr. H.Haddouti Introduction With the release of Oracle 9i, Oracle introduced the beginnings of an enhanced XML facility built into the database kernel itself. In Oracle 9i Release 1 (9.0), this meant the introduction of a new datatype, XMLType, as both a column, table, and a PL/SQL datatype. In Oracle 9i Release 2 (9.2), the functionality of this datatype was been greatly enhanced, coupled with an XML Repository that supports various protocols and complemented with additional capabilities like Context searching support, indexing, XQUERY support (still in beta version), schema validation and a host of other features that comprise what Oracle calls their XML DB facility. XML has arrived as a key technology for the next stage of evolution of the Internet. In the Today, most application data and web content is stored either in a relational database or the file system or a combination of both. XML is used mostly as an artifact for transport, generated from a database or a file-system. However, as the volume of XML being transported grows, and developers consider the costs of constant regeneration of XML documents there arises the question whether these storage methods effectively accommodate XML content. Figure 1: Common XML Architectures Oracle and XML Oracle has been at the forefront of XML technology for quite a while and, from the beginning Oracle has taken the approach of implementing the various different XML standards, which have largely been defined by the W3C. To provide higher performance and enhanced functionality, the XML functions of Oracle needed to be integrated into the database. Oracle took the first steps towards this integration with the inclusion of the XMLType datatype in 9.1. This release was a first step but true XML and Database integration did not occur until the enhanced version of the XMLType datatype and other additional functionality was added with release 9.2. What is XML DB? XML DB takes the XML support for Oracle to the next level. The XDK offered by Oracle is essentially a facility that is external to the database. With XML DB, this facility is now an integral part of the database kernel itself. This integration allows for a higher level of performance than previously available when handling XML documents and datagrams. This performance enhancement is provided through a number of capabilities including the ability to create Oracle indices for XML documents and to only update portions of an XML document, a facility known as a “lazily materialized virtual DOM”. The architecture of XML DB divides these facilities into two separate components. The first component can be considered an XML Repository built into the database. This repository rivals some of the existing XML databases and, to a large extent, obviates the need to have a separate database for handling XML content. XML DB’s Repository consists of a protocol handler that provides access to XML documents through standard Internet protocols including HTTP, FTP and WebDAV. These protocols essentially provide a Foldering paradigm for storing and retrieving XML documents. Additional features like versioning and Access Control Lists (ACLs) are also available. This component of the architecture, which implements the Content, or unstructured, view of XML DB. XMLType The XMLType datatype stores XML content, and can be used as the datatype of a column. XMLType includes a number of useful methods to operate on XML content. XMLTypes can be stored with 2 storage options – LOB and Object-Relational storage. The former storage model maintains accuracy to the original XML (whitespaces and all), while the latter maintains DOM (Document Object Model) fidelity. XMLType achieves DOM fidelity by maintaining information that SQL or Java objects normally don't provide for, such as: Ordering of child elements and attributes Distinguishing between elements and attributes Undeclared data in instance documents, such as processing instructions, comments, and namespace declarations Support for basic XML datatypes not available in SQL (Boolean etc.) Support for XML constraints (facets) not supported directly by SQL, such as enumerated lists. Some of the other benefits of XMLType are: XML Schema support: You can create tables and types automatically given a W3C standard XML Schema extending the normal SQL DDL. This means you have a standard data model for all your data (structured and unstructured), and can use the database to enforce this data model. XML Piecewise Update: You can use XPath to specify individual elements and attributes of your document to update, without rewriting the entire document. This is more efficient, especially for large XML documents. XPath Search: You can specify elements to query against via XPath, and then use SQL operators (conformant to the emerging ANSI SQLX standard ) on these elements. This helps you combine the best of SQL and XML. XML Indexes: Use XPath to specify parts of your document to create indexes for XPath searches. XML Operators: New operators like XMLTABLE (to cast a list of nodes returned by XPath into a table), XMLELEMENT (to create XML elements on the fly), etc. to make XML queries and on-the-fly XML generation easy. XML DB makes the SQL and XML metaphors interoperable. XSL Transformations for XMLType: Use an XSLT to transform XML documents via a SQL operator. Lazy XML Load: XMLType provides a virtual DOM; it only loads rows of data as they are requested, throwing away previously referenced sections of the document if memory usage grows too large. This helps you get high scalability when many concurrent users are dealing with large XML documents. XML Views: Create XML views to create permanent aggregations of various XML document fragments or relational tables. You can create your own efficient representations of XML. Schema Caching: XML DB keeps structural information (like element tags, datatypes, and storage location) in a schema cache, to minimize access time and storage costs. This helps you get high performance and scalability with large documents, as well as a large number of documents. Figure 1 – XML DB Architecture: the Content View (unstructured) The second component of the architecture implements the Data, or structured, view of the XML DB architecture. This component deals with SQL access to XML documents and provides the implementation of the XMLType datatype. The XMLType datatype allows for storing XML documents as exact replicas of an XML document in CLOB structures (“white space fidelity”) or with same order of elements as the original XML document (“DOM fidelity”) in object-relational tables. This component also provides additional features including the ability to register and validate against XML schemas, inclusion of XPath queries within SQL queries, the ability to perform XSL transformations and the creation of XML documents using SQL/XML queries. The Data view of the architecture of XML DB, is shown in Figure 2. One important point to note about XML DB is that XML schemas are supported but older style Document Type Definitions (DTDs) are not. Figure 2 – XML DB Architecture: the Data View (structured) An XML DB Example Much of the functionality of XML DB derives from the newly introduced XMLType datatype. When creating relational tables, either a single column can be associated with the XMLType datatype or the entire table can be just one column of this datatype. XML columns can bed defined when a table is created or added later using the ALTER TABLE statement. XMLType columns can also be dropped and have NULL values constraints associated with them. In PL/SQL, a parameter, a return value, a variable, a PL/SQL table, or a field on a PL/SQL record can be declared as an XMLType. The XML data in an XMLType column can optionally be associated with an XML schema. To complete this example, we will: 1. Register the XML schema with XML DB 2. Create a relational table to hold both relational data and XML documents 3. Load an XML document into the table 4. Write an SQL query to retrieve data from both the relational fields and the XML document in the same query All the queries to accomplish this example are included in the sql.txt. You can find all the necessary resources also in my website: http://stud.alakhawayn.ma/~991BE740226/ CONCLUSION XML DB is a high-performance XML storage and retrieval technology available with the Oracle9i Rel 2 server. It fully absorbs the W3C XML data model into the Oracle server, and provides new standard access methods for navigating and querying XML. With XML DB, you get all the advantages of relational database technology and XML technology at the same time. Functions and Procedures of XMLType Summary of Functions and Procedures of XMLType Function Description XMLType() Constructor that constructs an instance of the XMLType datatype. The constructor can take in the XML as a CLOB, VARCHAR2 or take in a object type. createXML() Static function for creating and returning an XMLType instance. existsNode() Takes a XMLType instance and a XPath and returns 1 or 0 indicating if applying the XPath returns a nonempty set of nodes. extract() Takes a XMLType instance and an XPath, applies the XPath expression and returns the results as an XMLType. isFragment() Checks if the input XMLType instance is a fragment or not. A fragment is a XML instance, which has more than one root element. getClobVal() Returns the value of the XMLtype instance as a CLOB getNumVal() Returns the value of the XMLtype instance as a NUMBER. This is only valid if the input XMLtpye instance contains a simple text node and is convertible to a number. getStringVal() Returns the value of the XMLType instance as a string. Function Description transform() Takes an XMLtype instance and an associated stylesheet (which is also an XMLtype instance) , applies the stylesheet and returns the result as XML. toObject() Converts the XMLType instance to an object type. isSchemaBased() Returns 1 or 0 indicating if the input XMLType instance is a schema based one or not. getSchemaURL() Returns the XML schema URL if the input is a XMLSchema based. getRootElement() Returns the root element of the input instance. Returns NULL if the instance is a fragment createSchemaBasedXML() Creates a schema based XMLtype instance from the non-schema based instance using the input schema URL. createNonSchemaBasedXML() Creates a non schema based XML from the input schema based instance. getNamespace() Returns the namespace for the top level element in a schema based document. schemaValidate() Validates the input instance according to the XMLSchema. Raises error if the input instance is non-schema based. isSchemaValidated() Checks if the instance has been validated against the schema. setSchemaValidated() Sets the schema valid flag to avoid costly schema validation. isSchemaValid() Checks if the input instance is schema valid according to the given schema URL.