Team Fly 

Page 286

An XML Schema is registered by the PL/SQL procedure called dbms_xmlschema.register_schema(). The XML Schema is registered under a URL, which is used internally as a unique key to identify the XML Schema. At no point does Oracle XML DB require direct access to the URL specified when registering the XML Schema.

The following listing demonstrates the use of dbms_xmlschema.registerSchema(), which is called within a PL/SQL procedure:

SQL> begin
  2  dbms_xmlschema.registerSchema (
  3  'http://xteoma.com/xsd/purchaseorder.xsd',
  4  xdbURIType('/xsd/purchaseorder.xsd').getClob(),
  5  True, True, False, True);
  6  end;
  7  /

Loading XML Data

As mentioned in the previous sections, loading XML documents into the Oracle XML DB repository database can be done by a simple insert statement from SQL or PL/SQL. Data being stored within an XMLType defined column is actually converted into an XMLType instance or object. Like all objects, when an instance XMLType is defined, it must use one of a number of variant constructors to instantiate itself. XMLType has defined constructors that can provide options for reducing the amount of processing associated with creating the XMLType. For instance, if the source XML document is known to be both well-formed and valid, the constructor allows flags to be passed that disable the default checking that is typically performed when instantiating the XMLType.

In the listing that follows, we are using the default constructor that has the XML document as its only argument. Using this provides for the validation of data by default.

SQL> insert into PURCHASE_ORDER
 2  values (67, XMLTYPE('
 3  <PurchaseOrder xmlns:xsi=''http://www.w3.org/2001/XMLSchema-instance"
 4     xsi:noNamespaceSchemaLocation="http://xteoma.com/xsd/purchaseorder.xsd">
 5     <Reference>MALLIA-20040109123337403PDT</Reference>
 6     <Requestor>Sean Mallia</Requestor>
 7     <User>SHAUNA</User>
 8     <ShippingInstructions>
 9        <name>Paddy Mallia</name>
10             <address>249 Kracqueric Ave.
11  Ottawa
12  ON
13  K1A 1A1
14  Canada</address>
15             <telephone>613 555-2620</telephone>
Team Fly 
0305