Presentation is loading. Please wait.

Presentation is loading. Please wait.

Outline ► Why XML in the Database ► What is XML DB? ► XML DB Architecture ► The XMLType Datatype ► Example1:  Schemas Registration  Inserting and Querying.

Similar presentations


Presentation on theme: "Outline ► Why XML in the Database ► What is XML DB? ► XML DB Architecture ► The XMLType Datatype ► Example1:  Schemas Registration  Inserting and Querying."— Presentation transcript:

1

2 Outline ► Why XML in the Database ► What is XML DB? ► XML DB Architecture ► The XMLType Datatype ► Example1:  Schemas Registration  Inserting and Querying Data  Creating and Using Indices ► The XML DB Repository ► The XML DB APIs ► XML Future Additions ► Summary

3 Common XML Architectures

4 Why XML in the Database? ► Reduce maintenance costs of extra moving parts; i.e. XML middleware.  Eliminate separate ‘XML-processing’ layers ► Keep applications standards-based  W3C, IETF, ANSI/ISO, J2EE  Eliminate proprietary file formats, message formats, delimited columns ► Enable richer semantics and better management for content-oriented applications  Store as XML vs. Files or LOBs  Queryability

5 Oracle and XML ► Oracle has been at the forefront of XML technology for quite a while. ► From the beginning Oracle implemented the various different XML standards, which have largely been defined by the W3C. ► Oracle XML parser: SAX and DOM APIs. ► XSLT transformations and support for the initial XML Schema proposals ► Etc… ahead of time.

6 ORACLE XML DB Features ► With Oracle XML DB, you get all the advantages of relational database technology and XML technology at the same time. ► Oracle XML DB provides an independent infrastructure to store and manage XML data:  storage-independent  content-independent  programming language-independent

7 ORACLE XML DB ► Oracle XML DB is the term used to describe the technology in the Oracle 9i Release 2 database for supporting XML ► Extends the popular Oracle relational database  Keeps all the functionality of RDBMS  Provides all of the functionality associated with a native XML database ► Delivers high-performance storage and retrieval of XML.

8 XML Support in Oracle 9i R2 XMLType XMLType XML Repository XML Repository

9 XML DB Architecture - Data View

10 XML DB Architecture - Content View

11 The XMLType Datatype Definition ► “XMLType is a native data-type that is used to store and manage XML documents in columns or tables”

12 The XMLType Datatype ► Introduced with Oracle 9i Rel. 1 to store XML data in the database ► Enhanced extensively in 9i Rel. 2 ► XMLType is a native server data-type  allows the database to understand that a column or table contains XML  same way as DATE data-type

13 The XMLType Datatype ► XMLType is an object type ► In tables: xmltype can either be used as data-type for a column or an entire table create table orders create table orders ( orderNo NUMBER(10), orderNo NUMBER(10), customerId NUMBER(8), customerId NUMBER(8), xmlorder XMLTYPE, xmlorder XMLTYPE, date_entered DATE date_entered DATE )-------------------------------------- create table orders of XMLTYPE create table orders of XMLTYPE

14 The XMLType Datatype ► XMLType is an object type  In PL/SQL: a parameter, a return value, a PL/SQL table, a record or a variable can be declared as an XMLTYPE

15 The XMLType Datatype ► The XMLType data type can also be used when defining views:  XMLType view  relational view that includes an XMLType column ► This allows to expose content stored in relational tables and external data sources as XML documents.

16 The XMLType Datatype ► XMLType has a number of built-in member functions for creating, extracting and indexing XML data ► Allows access to the XML data using standard XPath expressions ► A new 9.0.2 operator, XMLTransform, allows for XSL transformations ► The XML data can optionally be based on a W3C schema

17 The XMLType Member Functions XML DB provides a number of functions for querying and updating XML data. The most important of these functions are: ► extract (xmltype,xpath) extracts a subset of nodes, or an XML fragment, from an XML document ► existsNode (xmltype,xpath) checks whether or not a particular node exists in the XMLType, it is often found as part of a WHERE clause statement ► extractValue( xmltype,xpath ) extracts the value of a single node in an XML document using an XPath expression ► updateXML() updates an entire XML document or a portion of the XML document in the database

18 The XMLType Member Functions ► schemaValidate () Validates the contents of the XMLType against an XML Schema ► transform () XSL Transformation ► getClobVal() Returns the document as a CLOB. ► getNumVal() Returns the fragment or text value in the XMLType to a number. ► getStringVal() Returns the document as a string.

19 XMLType Data Storage ► XMLType data can be stored in one of two ways:  In CLOB storage to maintain the original XML content  In Structured storage (tables and views) to maintain DOM fidelity

20 XMLType Data Storage ► When you create an XMLType column without an XML schema, a hidden CLOB column is automatically created ► The hidden column stores the extra non- SQL based information

21 CLOB VS. Structured Storage

22

23

24 XML Piecewise Update ► ► When using Structured Storage:   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.

25 XMLType Data Storage ► Constraining a column or table to an XML Schema has a number of advantages:  The database will store only valid XML documents  Oracle XML DB can use the information contained in the XML Schema to provide more intelligent query and update processing of the XML. ► One important point to note: DTDs are not supported.

26 XMLType: Virtual DOM ► DOM problem: to operate on a document, the whole document has to be an object model in memory. ► With large documents, that can be a serious problem. ► Virtual DOM: however, allows users to materialize a DOM on the fly while processing requests (a "virtual" or "lazy" DOM), rather than doing it all at once; it only loads the data trees as they are requested, throwing away previously- referenced sections of the document if memory usage grows too large. This feature is completely transparent.

27 XMLType: Schema Validation ► Oracle XML DB does not automatically perform a full schema validation of documents as they are inserted into the database. ► Why? ► Schema validation is a fairly CPU intensive operation. ► The development team decided to make full schema validation optional. ► Full schema validation can be enabled on a Schema by Schema basis using a Check Constraint or Trigger.

28 XMLType: Schema Validation ► By default, Oracle XML DB performs a light weight validation of each document. It checks that mandatory elements and attributes are present, and that number of elements within a collection is compliant with the values defined in the XMLSchema ► It does not check pattern matches, minimum lengths etc. This is a performance optimization.

29 ► XMLType Datatype Example

30 Example: Scenario  A mediator Company that offers many products from different suppliers  The client buys from different suppliers

31 Example: Steps To Accomplish ► 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  Whole Document  Data from both the relational fields and the XML document in the same query 5. Update an XML field 6. Create Indexes

32 Example: Schema File http://stud.alakhawayn.ma/~991BE740226/schema/order.xsd

33 ► ►

34 Example: XML File http://stud.alakhawayn.ma/~991BE740226/schema/order1.xml

35 ► ► ► 2003-08-28 ► 2003-08-28 ► ► ► Miloud Company ► Miloud Company ► SL35-721 ► SL35-721 ► 17.97 ► 17.97 ► 12 ► 12 ► ► ► Spezi Company ► Spezi Company ► CP01-487 ► CP01-487 ► 162.75 ► 162.75 ► 5 ► 5 ► ► ► Kamal BO Company ► Kamal BO Company ► ML32-42 ► ML32-42 ► 12.25 ► 12.25 ► 5 ► 5 ► ► ► Al-Watania Company ► Al-Watania Company ► KP96-351 ► KP96-351 ► 16.70 ► 16.70 ► 5 ► 5 ► ► ► Bouchta Company ► Bouchta Company ► CT01-365 ► CT01-365 ► 62.05 ► 62.05 ► 5 ► 5 ► ►

36 Registering a Schema ► Before using an XML schema, it must be registered with the database ► This is accomplished using the DBMS_XMLSCHEMA package ► The two main functions are registerSchema and deleteSchema

37 Registering an XML Schema exec DBMS_XMLSCHEMA.registerSchema( schema URL, schema source document) schema URL, schema source document) ► The XML schema source document can be define as a VARCHAR, a CLOB, an XMLType or a URIType ► Registering an XML schema adds a resource to the XML DB repository ► A Schema can be registered locally or globally

38 Registering an XML Schema ► By default, schemas are loaded locally and associated with the “database schema” they are created under ► BEGIN ► DBMS_XMLSCHEMA.REGISTERSCHEMA( ► schemaurl=>'http://stud.alakhawayn.ma/~991BE740226/schema/order.xsd', schemadoc=>sys.UriFactory.getUri('http://stud.alakhawayn.ma/~991BE740226/sc hema/order.xsd')); ► END; ► /

39 Creating a Relational Table with XML Data ► create table orders( ► orderNo NUMBER(10), ► customerId NUMBER(8), ► xmlOrder XMLTYPE, ► date_entered DATE ) ► XMLTYPE COLUMN xmlOrder  STORE AS CLOB  STORAGE (INITIAL 4096 NEXT 4096)  XMLSCHEMA “http://stud.alakhawayn.ma/~991BE740226/schema/order.xsd” ELEMENT “order”  ;

40 Inserting, Querying and Updating ► XML data is inserted into an XMLType column using the XMLType() constructor INSERT INTO ORDERS (orderNo,customerId, INSERT INTO ORDERS (orderNo,customerId, xmlOrder, date_entered) xmlOrder, date_entered) VALUES (orderNoSeq.nextval, 6135, VALUES (orderNoSeq.nextval, 6135, XMLTYPE(‘ XMLTYPE(‘ ► ► ► 2003-08-28 ► 2003-08-28 ► ► ► Miloud Company ► Miloud Company ► SL35-721 ► SL35-721 ► 17.97 ► 17.97 ► 12 ► 12 ► ► ► Spezi Company ► Spezi Company ► CP01-487 ► CP01-487 ► 162.75 ► 162.75 ► 5 ► 5 ► ► ► SOMAPHA Company ► SOMAPHA Company ► ML32-42 ► ML32-42 ► 12.25 ► 12.25 ► 5 ► 5 ► ► ► Al-Watania Company ► Al-Watania Company ► KP96-351 ► KP96-351 ► 16.70 ► 16.70 ► 5 ► 5 ► ► ► Bouchta Company ► Bouchta Company ► CT01-365 ► CT01-365 ► 62.05 ► 62.05 ► 5 ► 5 ► ► '), SYSDATE)

41 Inserting, Querying and Updating ► The XML document can be retrieved in a query using getClobVal() ► select o.xmlOrder.getClobVal() from ORDERS o WHERE o.xmlOrder.existsNode('/order/items')= 1 WHERE o.xmlOrder.existsNode('/order/items')= 1 ► select extract(o.xmlOrder,’/’) from ORDERS o WHERE o.xmlOrder.existsNode('/order/items')= 1 WHERE o.xmlOrder.existsNode('/order/items')= 1

42 Hint ► In order to display many lines of the XML result in the sql*plus: ► set long 10000 ► Set pagesize 10000

43 Inserting, Querying and Updating ► You can even combine both types of access into a single SQL query SELECT orderNo, customerId, extractValue(xmlOrder, '/order/fillByDate') FillByDate, date_entered FROM orders

44 Inserting, Querying and Updating ► The XML document can be updated using ► update orders SET xmlOrder = updateXML(xmlOrder, '/order/items/item[2]/qty/text()',10); '/order/items/item[2]/qty/text()',10);

45 Creating XMLType Indices ► Indices can be created on XMLType columns ► These indices can either be function- based using extract() or existNodes(). Latter is better for bit-mapped indexes

46 Creating XMLType Indices ► CREATE INDEX FillBy_NDX ON ORDERS (xmlOrder.extract('/order/fillByDate'). (xmlOrder.extract('/order/fillByDate'). getStringVal()); getStringVal()); ► CREATE BITMAP INDEX MultItems_NDX ON ORDERS (xmlOrder.existsNode('/order/items/ (xmlOrder.existsNode('/order/items/ item/supplier')); item/supplier'));

47 Creating Context Indexes ► Oracle ConText indexes can be defined for XMLTypes columns or tables CREATE INDEX co_ctx_ndx ON orders(xmlOrder) indextype is ctxsys.context; CREATE INDEX co_ctx_ndx ON orders(xmlOrder) indextype is ctxsys.context; ► Operation such as CONTAINS can then be used

48 The XMLType/XML DB APIs ► XMLType Member Functions ► SYS_XMLGEN, SYS_XMLAGG and DBMX_XMLGEN ► SQL/XML Functions ► PL/SQL DOM API (DBMS_XMLDOM) ► PL/SQL Parser API (DBMS_XML_PARSER) ► XSLT Processor (DBMS_XSL_ PROCESSOR) ► DBMS_XDBT (Context indexes) ► The XML DB Repository views

49 ► XML DB Repository

50 XML DB Repository ► It is possible to have your cake and eat it too ► You can store your document as a Native XML Type in Oracle's XML DB repository, which will preserve byte-by-byte document fidelity and also shred it into SQL tables.

51 XML DB Repository ► When your XML schema is registered, you store your XML data in your database, by simply inserting an XML document file using SQL, PL/SQL, Java, FTP, HTTP, or WebDAV. ► Getting XML data out of your database can be as simple as executing a SQL query or reading a file using one of those Internet- standard protocols.

52 XML DB Repository Features ► Provides access to XML content using a foldering metaphor ► Includes ACLs (Access Control Lists) to control secured access to XML data ► Access includes HTTP, WedDAV and FTP ► WebDAV provides directory-like access to XML from any WebDAV-enabled device such as Windows desktops ► FTP access is provided for XML application development requiring file transfers ► Document versioning is also available

53

54 XML DB Repository ► There are many advantages to the XML DB repository, but it isn't right for every application. ► Overhead is involved in maintaining the relationship between the full document and its shredded data.

55 XML DB Repository ► However, the biggest problem comes with schema evolution. ► That means you can't do most nontrivial changes of either the database or the document schema, without having to export all the data and re-import it into the database.

56 XML DB: Comming Soon ► In the future, Oracle is looking at adding several new capabilities: ► XQuery: which will be a language specifically designed to query XML data from a document perspective, rather than the rows-and-tables perspective of SQL. ► (A prototype of XQuery language is available for download on OTN.) download

57 Summary

58 Oracle XML DB ► Oracle XML DB  Adds native support for the emerging XML standards to the popular Oracle database  Brings SQL and XML processing together  introduces a number of innovations needed for efficient storage and retrieval of XML.

59 XML-Type Summay ► XML can be stored one of two ways:  An XMLType column 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.

60 CLOB vs. Structured Storage Unstructured Whole document Original content Mediocre for DML Can be large Structured Decomposed DOM Fidelity Excellent for DML Less space Format Storage Integrity Performance Space Feature CLOB Structured

61 References ► 1. Oracle 9i XML Database Developer's Guide: Appendix A – Installing and Configuring XML DB. (http://otn.oracle.com/tech/xml/doc.html) ► 2. Oracle 9i: XML API Reference. (http://otn.oracle.com/tech/xml/doc.html) ► 3. W3C XML 1.0 Recommendation. (http://www.w3.org/TR/REC-xml) ► 4. W3C XML Schema Recommendation. (http://www.w3.org/TR/xmlschema-1 and http://www.w3.org/TR/xmlschema-2 ) ► 5. Altova's XML Spy. (http://www.xmlspy.com) ► 6. Oracle 9i XML Database Developer's Guide: Appendix G – Example Setup Scripts. At the beginning of this section, there is a script that you can run to create a directory to contain your schemas and XML documents as well as for getDocument() procedure to load these files into XML DB (http://otn.oracle.com/tech/xml/doc.html)

62


Download ppt "Outline ► Why XML in the Database ► What is XML DB? ► XML DB Architecture ► The XMLType Datatype ► Example1:  Schemas Registration  Inserting and Querying."

Similar presentations


Ads by Google