[11g] XML Schema full validation with binary XML ?

Hi,
Oracle's doc quotes " Loading XML data into XML schema-based binary XML storage causes full validation against the target XML schemas. ".
After registering this XML Schema which indicates that a company must have at least a code, name and pilotes element :
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xdb="http://xmlns.oracle.com/xdb"
xdb:storeVarrayAsTable="true" version="1.0">
<xsd:element name="compagnie" type="compagnieType"/>
<xsd:complexType name="compagnieType">
<xsd:sequence>
<xsd:element name="comp" type="compType" minOccurs="1" xdb:SQLName="COMP"/>
<xsd:element name="pilotes" type="pilotesType" minOccurs="1" xdb:SQLName="PILOTES"/>
<xsd:element name="nomComp" type="nomCompType" minOccurs="1" xdb:SQLName="NOMCOMP"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="pilotesType">
<xsd:sequence>
<xsd:element minOccurs="1" maxOccurs="unbounded"
name="pilote" type="piloteType" xdb:SQLName="PILOTE"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="piloteType">
<xsd:sequence>
<xsd:element name="nom" type="nomType" xdb:SQLName="NOM"/>
<xsd:element name="salaire" type="salaireType" minOccurs="0"
     xdb:SQLName="SALAIRE"/>
</xsd:sequence>
<xsd:attribute name="brevet" xdb:SQLName="BREVET">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:minLength value="1"/>
<xsd:maxLength value="4"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
I can therefore insert a row no valid into this table
CREATE TABLE compagnie_binaryXML_grammaire OF XMLType
XMLTYPE STORE AS BINARY XML
XMLSCHEMA "http://www.soutou.net/compagnies3.xsd"
ELEMENT "compagnie"
ALLOW NONSCHEMA
VIRTUAL COLUMNS (vircolcomp AS (EXTRACTVALUE(OBJECT_VALUE,'/compagnie/comp')));
SQL> INSERT INTO compagnie_binaryXML_grammaire VALUES
2 (XMLTYPE.CREATEXML('<?xml version="1.0" encoding="ISO-8859-1"?>
3 <compagnie>
4 <pilotes></pilotes>
5 <nomComp>No pilot and no comp!</nomComp>
6 </compagnie>').CREATESCHEMABASEDXML('http://www.soutou.net/compagnies3.xsd'
1 ligne crÚÚe.
Unless the following instruction is done, no valid XML file can be added.
ALTER TABLE compagnie_binaryXML_grammaire
     ADD CONSTRAINT valide_compagniebinaryXML
     CHECK (XMLIsValid(OBJECT_VALUE) = 1);
Where is the difference between the behaviour of an object-relational table ?

My guess is that the virtual column spoils the soup (could you check).
The following works for me on 11.1.0.6.0.
connect / as sysdba
drop user test cascade;
create user test identified by test;
grant xdbadmin, dba to test;
connect test/test
spool encoding_test01.txt
var schemaPath varchar2(256)
var schemaURL  varchar2(256)
set long 100000000
col SCHEMA_URL FOR a60
col object_name for a50
select * from v$version;
purge recyclebin;
alter session set recyclebin=OFF;
drop table VALIDATE_XML_SCHEMA;
prompt  Create Folder for TEST schema, user
declare
   retb boolean;
begin
  retb := dbms_xdb.createfolder('/test');
end;
prompt  =================================================================
prompt  Register Relational XML SChema
prompt  =================================================================
prompt  XML SChema
begin
  :schemaURL  := 'http://www.relational.com/root.xsd';
  :schemaPath := '/test/root_relational.xsd';
end;
prompt  Cleaning up
call  DBMS_XMLSCHEMA.deleteSchema(:schemaURL,4);
commit;
prompt  XSD Schema
declare
  res boolean;
  xmlSchema xmlType := xmlType(
'<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
            xmlns:xdb="http://xmlns.oracle.com/xdb"
            xmlns="http://www.relational.com/root.xsd" targetNamespace="http://www.relational.com/root.xsd"
            elementFormDefault="qualified"
            attributeFormDefault="unqualified"
            xdb:storeVarrayAsTable="true">
     <xs:element name="ROOT" xdb:defaultTable="ROOT_TABLE" xdb:maintainDOM="false">
          <xs:annotation>
               <xs:documentation>Example XML Schema</xs:documentation>
          </xs:annotation>
          <xs:complexType xdb:maintainDOM="false">
               <xs:sequence>
                    <xs:element name="ID" type="xs:integer" xdb:SQLName="ID"/>
                    <xs:element ref="INFO"/>
               </xs:sequence>
          </xs:complexType>
     </xs:element>
     <xs:element name="INFO" xdb:SQLName="INFO_TYPE">
          <xs:complexType xdb:maintainDOM="false">
               <xs:sequence>
                    <xs:element name="INFO_ID" type="xs:integer" xdb:SQLName="TYPE_INFO_ID"/>
                    <xs:element name="INFO_CONTENT"
                xdb:SQLName="TYPE_INFO_CONTENT" type="xs:string"/>
               </xs:sequence>
          </xs:complexType>
     </xs:element>
</xs:schema>');
begin
if (dbms_xdb.existsResource(:schemaPath)) then
    dbms_xdb.deleteResource(:schemaPath);
end if;
res := dbms_xdb.createResource(:schemaPath,xmlSchema);
end;
alter session set events='31098 trace name context forever';
BEGIN
  DBMS_XMLSCHEMA.registerSchema
  (SCHEMAURL => :schemaURL,
  SCHEMADOC => xdbURIType(:schemaPath).getClob(),
  LOCAL     => TRUE,   -- local
  GENTYPES  => FALSE,  -- generate object types
  GENBEAN   => FALSE,  -- no java beans
  GENTABLES => FALSE,  -- generate object tables
  OWNER     => USER);
END;
commit;
prompt  =================================================================
prompt  Register Binary XML SChema
prompt  =================================================================
prompt  XML SChema
begin
  :schemaURL  := 'http://www.binary.com/root.xsd';
  :schemaPath := '/test/root_binary.xsd';
end;
prompt  Cleaning up
call  DBMS_XMLSCHEMA.deleteSchema(:schemaURL,4);
commit;
prompt  XSD Schema
declare
  res boolean;
  xmlSchema xmlType := xmlType(
'<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
            xmlns:xdb="http://xmlns.oracle.com/xdb"
            xmlns="http://www.binary.com/root.xsd" targetNamespace="http://www.binary.com/root.xsd"
            elementFormDefault="qualified"
            attributeFormDefault="unqualified"
            xdb:storeVarrayAsTable="true">
     <xs:element name="ROOT" xdb:defaultTable="ROOT_TABLE" xdb:maintainDOM="false">
          <xs:annotation>
               <xs:documentation>Example XML Schema</xs:documentation>
          </xs:annotation>
          <xs:complexType xdb:maintainDOM="false">
               <xs:sequence>
                    <xs:element name="ID" type="xs:integer" xdb:SQLName="ID"/>
                    <xs:element ref="INFO"/>
               </xs:sequence>
          </xs:complexType>
     </xs:element>
     <xs:element name="INFO" xdb:SQLName="INFO_TYPE">
          <xs:complexType xdb:maintainDOM="false">
               <xs:sequence>
                    <xs:element name="INFO_ID" type="xs:integer" xdb:SQLName="TYPE_INFO_ID"/>
                    <xs:element name="INFO_CONTENT"
                xdb:SQLName="TYPE_INFO_CONTENT" type="xs:string"/>
               </xs:sequence>
          </xs:complexType>
     </xs:element>
</xs:schema>');
begin
if (dbms_xdb.existsResource(:schemaPath)) then
    dbms_xdb.deleteResource(:schemaPath);
end if;
res := dbms_xdb.createResource(:schemaPath,xmlSchema);
end;
alter session set events='31098 trace name context forever';
BEGIN
  DBMS_XMLSCHEMA.registerSchema
  (SCHEMAURL => :schemaURL,
  SCHEMADOC => xdbURIType(:schemaPath).getClob(),
  LOCAL     => TRUE,   -- local
  GENTYPES  => FALSE,  -- generate object types
  GENBEAN   => FALSE,  -- no java beans
  GENTABLES => FALSE,  -- generate object tables
  OPTIONS   => DBMS_XMLSCHEMA.REGISTER_BINARYXML,
  OWNER     => USER);
END;
commit;
prompt  =================================================================
prompt  Register SECOND Binary XML SChema
prompt  =================================================================
prompt  XML SChema
begin
  :schemaURL  := 'http://www.different.com/roots.xsd';
  :schemaPath := '/test/roots.xsd';
end;
prompt  Cleaning up
call  DBMS_XMLSCHEMA.deleteSchema(:schemaURL,4);
commit;
prompt  XSD Schema
declare
  res boolean;
  xmlSchema xmlType := xmlType(
'<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
            xmlns:xdb="http://xmlns.oracle.com/xdb"
            xmlns="http://www.different.com/roots.xsd" targetNamespace="http://www.different.com/roots.xsd"
            elementFormDefault="qualified"
            attributeFormDefault="unqualified"
            xdb:storeVarrayAsTable="true">
     <xs:element name="ROOTS" xdb:maintainDOM="false">
          <xs:annotation>
               <xs:documentation>Example XML Schema</xs:documentation>
          </xs:annotation>
          <xs:complexType xdb:maintainDOM="false">
               <xs:sequence>
                    <xs:element name="ID" type="xs:integer" xdb:SQLName="ID"/>
                    <xs:element ref="INFO"/>
               </xs:sequence>
          </xs:complexType>
     </xs:element>
     <xs:element name="INFO" xdb:SQLName="INFO_TYPE">
          <xs:complexType xdb:maintainDOM="false">
               <xs:sequence>
                    <xs:element name="INFO_ID" type="xs:integer" xdb:SQLName="TYPE_INFO_ID"/>
                    <xs:element name="INFO_CONTENT"
                xdb:SQLName="TYPE_INFO_CONTENT" type="xs:string"/>
               </xs:sequence>          </xs:complexType>
     </xs:element>
</xs:schema>');
begin
if (dbms_xdb.existsResource(:schemaPath)) then
    dbms_xdb.deleteResource(:schemaPath);
end if;
res := dbms_xdb.createResource(:schemaPath,xmlSchema);
end;
alter session set events='31098 trace name context forever';
BEGIN
  DBMS_XMLSCHEMA.registerSchema
  (SCHEMAURL => :schemaURL,
  SCHEMADOC => xdbURIType(:schemaPath).getClob(),
  LOCAL     => TRUE,   -- local
  GENTYPES  => FALSE,  -- generate object types
  GENBEAN   => FALSE,  -- no java beans
  GENTABLES => FALSE,  -- generate object tables
  OPTIONS   => DBMS_XMLSCHEMA.REGISTER_BINARYXML,
  OWNER     => USER);
END;
commit;
prompt  =================================================================
prompt  END Registration Process
prompt  =================================================================
select xmlType(xdbURIType ('/test/root.xsd').getClob())
from   dual;
alter session set events='31098 trace name context forever';
select schema_url, binary
from   user_xml_schemas;
select * from tab;
select object_name, object_type from user_objects;
prompt  =================================================================
prompt  BASICFILE - XMLSCHEMA (default) - DISALLOW NONSCHEMA
prompt  =================================================================
drop table "VALIDATE_XML_SCHEMA";
create table "VALIDATE_XML_SCHEMA" of XMLTYPE
XMLTYPE STORE AS BASICFILE BINARY XML
XMLSCHEMA "http://www.binary.com/root.xsd"
  ELEMENT "ROOT";
prompt  No schema defined
insert into "VALIDATE_XML_SCHEMA"
values
(xmltype('<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
  <ID>0</ID>
  <INFO>
    <INFO_ID>0</INFO_ID>
    <INFO_CONTENT>Text</INFO_CONTENT>
  </INFO>
</ROOT>'))
prompt  Bogus, noexistent schema defined
insert into "VALIDATE_XML_SCHEMA"
values
(xmltype('<?xml version="1.0" encoding="UTF-8"?>
<ROOT xmlns="http://www.bogus.com/root.xsd">
  <ID>0</ID>
  <INFO>
    <INFO_ID>0</INFO_ID>
    <INFO_CONTENT>Text</INFO_CONTENT>
  </INFO>
</ROOT>'))
prompt  Binary schema defined
insert into "VALIDATE_XML_SCHEMA"
values
(xmltype('<?xml version="1.0" encoding="UTF-8"?>
<ROOT xmlns="http://www.binary.com/root.xsd">
  <ID>0</ID>
  <INFO>
    <INFO_ID>0</INFO_ID>
    <INFO_CONTENT>Text</INFO_CONTENT>
  </INFO>
</ROOT>'))
prompt  Binary schema with different location path
insert into "VALIDATE_XML_SCHEMA"
values
(xmltype('<?xml version="1.0" encoding="UTF-8"?>
<ROOTS xmlns="http://www.different.com/roots.xsd">
  <ID>0</ID>
  <INFO>
    <INFO_ID>0</INFO_ID>
    <INFO_CONTENT>Text</INFO_CONTENT>
  </INFO>
</ROOTS>'))
prompt  Binary schema with incorrect "root(s)"
insert into "VALIDATE_XML_SCHEMA"
values
(xmltype('<?xml version="1.0" encoding="UTF-8"?>
<ROOT xmlns="http://www.different.com/roots.xsd">
  <ID>0</ID>
  <INFO>
    <INFO_ID>0</INFO_ID>
    <INFO_CONTENT>Text</INFO_CONTENT>
  </INFO>
</ROOT>'))
prompt  Relational registered schema
insert into "VALIDATE_XML_SCHEMA"
values
(xmltype('<?xml version="1.0" encoding="UTF-8"?>
<ROOT xmlns="http://www.relational.com/root.xsd">
  <ID>0</ID>
  <INFO>
    <INFO_ID>0</INFO_ID>
    <INFO_CONTENT>Text</INFO_CONTENT>
  </INFO>
</ROOT>'))
prompt  =================================================================
prompt  BASICFILE - XMLSCHEMA - ALLOW NONSCHEMA
prompt  =================================================================
drop table "VALIDATE_XML_SCHEMA";
create table "VALIDATE_XML_SCHEMA" of XMLTYPE
XMLTYPE STORE AS BASICFILE BINARY XML
XMLSCHEMA "http://www.binary.com/root.xsd"
  ELEMENT "ROOT"
ALLOW NONSCHEMA;
prompt  No schema defined
insert into "VALIDATE_XML_SCHEMA"
values
(xmltype('<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
  <ID>0</ID>
  <INFO>
    <INFO_ID>0</INFO_ID>
    <INFO_CONTENT>Text</INFO_CONTENT>
  </INFO>
</ROOT>'))
prompt  Bogus, noexistent schema defined
insert into "VALIDATE_XML_SCHEMA"
values
(xmltype('<?xml version="1.0" encoding="UTF-8"?>
<ROOT xmlns="http://www.bogus.com/root.xsd">
  <ID>0</ID>
  <INFO>
    <INFO_ID>0</INFO_ID>
    <INFO_CONTENT>Text</INFO_CONTENT>
  </INFO>
</ROOT>'))
prompt  Binary schema defined
insert into "VALIDATE_XML_SCHEMA"
values
(xmltype('<?xml version="1.0" encoding="UTF-8"?>
<ROOT xmlns="http://www.binary.com/root.xsd">
  <ID>0</ID>
  <INFO>
    <INFO_ID>0</INFO_ID>
    <INFO_CONTENT>Text</INFO_CONTENT>
  </INFO>
</ROOT>'))
prompt  Binary schema with different location path
insert into "VALIDATE_XML_SCHEMA"
values
(xmltype('<?xml version="1.0" encoding="UTF-8"?>
<ROOTS xmlns="http://www.different.com/roots.xsd">
  <ID>0</ID>
  <INFO>
    <INFO_ID>0</INFO_ID>
    <INFO_CONTENT>Text</INFO_CONTENT>
  </INFO>
</ROOTS>'))
prompt  Binary schema with incorrect "root(s)"
insert into "VALIDATE_XML_SCHEMA"
values
(xmltype('<?xml version="1.0" encoding="UTF-8"?>
<ROOT xmlns="http://www.different.com/roots.xsd">
  <ID>0</ID>
  <INFO>
    <INFO_ID>0</INFO_ID>
    <INFO_CONTENT>Text</INFO_CONTENT>
  </INFO>
</ROOT>'))
prompt  Relational registered schema
insert into "VALIDATE_XML_SCHEMA"
values
(xmltype('<?xml version="1.0" encoding="UTF-8"?>
<ROOT xmlns="http://www.relational.com/root.xsd">
  <ID>0</ID>
  <INFO>
    <INFO_ID>0</INFO_ID>
    <INFO_CONTENT>Text</INFO_CONTENT>
  </INFO>
</ROOT>'))
-- Output
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
PL/SQL Release 11.1.0.6.0 - Production
CORE     11.1.0.6.0     Production
TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
NLSRTL Version 11.1.0.6.0 - Production
5 rows selected.
Recyclebin purged.
Session altered.
drop table VALIDATE_XML_SCHEMA
ERROR at line 1:
ORA-00942: table or view does not exist
Create Folder for TEST schema, user
declare
ERROR at line 1:
ORA-31003: Parent / already contains child entry test
ORA-06512: at "XDB.DBMS_XDB", line 316
ORA-06512: at line 4
=================================================================
Register Relational XML SChema
=================================================================
XML SChema
PL/SQL procedure successfully completed.
Cleaning up
call  DBMS_XMLSCHEMA.deleteSchema(:schemaURL,4)
ERROR at line 1:
ORA-31000: Resource 'http://www.relational.com/root.xsd' is not an XDB schema document
ORA-06512: at "XDB.DBMS_XMLSCHEMA_INT", line 106
ORA-06512: at "XDB.DBMS_XMLSCHEMA", line 102
ORA-06512: at line 1
Commit complete.
XSD Schema
PL/SQL procedure successfully completed.
Session altered.
PL/SQL procedure successfully completed.
Commit complete.
=================================================================
Register Binary XML SChema
=================================================================
XML SChema
PL/SQL procedure successfully completed.
Cleaning up
call  DBMS_XMLSCHEMA.deleteSchema(:schemaURL,4)
ERROR at line 1:
ORA-31000: Resource 'http://www.binary.com/root.xsd' is not an XDB schema document
ORA-06512: at "XDB.DBMS_XMLSCHEMA_INT", line 106
ORA-06512: at "XDB.DBMS_XMLSCHEMA", line 102
ORA-06512: at line 1
Commit complete.
XSD Schema
PL/SQL procedure successfully completed.
Session altered.
PL/SQL procedure successfully completed.
Commit complete.
=================================================================
Register SECOND Binary XML SChema
=================================================================
XML SChema
PL/SQL procedure successfully completed.
Cleaning up
call  DBMS_XMLSCHEMA.deleteSchema(:schemaURL,4)
ERROR at line 1:
ORA-31000: Resource 'http://www.different.com/roots.xsd' is not an XDB schema document
ORA-06512: at "XDB.DBMS_XMLSCHEMA_INT", line 106
ORA-06512: at "XDB.DBMS_XMLSCHEMA", line 102
ORA-06512: at line 1
Commit complete.
XSD Schema
PL/SQL procedure successfully completed.
Session altered.
PL/SQL procedure successfully completed.
Commit complete.
=================================================================
END Registration Process
=================================================================
Session altered.
SCHEMA_URL                                                   BIN
http://www.relational.com/root.xsd                           NO
http://www.binary.com/root.xsd                               YES
http://www.different.com/roots.xsd                           YES
3 rows selected.
no rows selected
no rows selected
=================================================================
BASICFILE - XMLSCHEMA (default) - DISALLOW NONSCHEMA
=================================================================
drop table "VALIDATE_XML_SCHEMA"
ERROR at line 1:
ORA-00942: table or view does not exist
Table created.
No schema defined
(xmltype('<?xml version="1.0" encoding="UTF-8"?>
ERROR at line 3:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LSX-00021: undefined element "ROOT"
Bogus, noexistent schema defined
(xmltype('<?xml version="1.0" encoding="UTF-8"?>
ERROR at line 3:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LSX-00023: unknown namespace URI "http://www.bogus.com/root.xsd"
Binary schema defined
1 row created.
Binary schema with different location path
(xmltype('<?xml version="1.0" encoding="UTF-8"?>
ERROR at line 3:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LSX-00023: unknown namespace URI "http://www.different.com/roots.xsd"
Binary schema with incorrect "root(s)"
(xmltype('<?xml version="1.0" encoding="UTF-8"?>
ERROR at line 3:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LSX-00023: unknown namespace URI "http://www.different.com/roots.xsd"
Relational registered schema
(xmltype('<?xml version="1.0" encoding="UTF-8"?>
ERROR at line 3:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LSX-00023: unknown namespace URI "http://www.relational.com/root.xsd"
=================================================================
BASICFILE - XMLSCHEMA - ALLOW NONSCHEMA
=================================================================
Table dropped.
Table created.
No schema defined
1 row created.
Bogus, noexistent schema defined
1 row created.
Binary schema defined
1 row created.
Binary schema with different location path
1 row created.
Binary schema with incorrect "root(s)"
1 row created.
Relational registered schema
1 row created.

Similar Messages

  • How can I define an XML schema for this kind of XML

    Hi, There:
    I want to generate an XML file like:
    <customer>
    </customer>
    <transaction>
    </transaction>
    <customer>
    </customer>
    which have multiple customer elements and multiple transactions as well, and they can happen in mixed sequence. Can any one give me some idea about how can I create an XML schema for this kind of xml? (<xsd:complextype> <xsd:sequence> ) seems not work)
    Thanks in advance
    David

    Use a group then make it a choice, like this;
    <xs:element name="Parent">
    <xs:complexType>
    <xs:group ref="Group" minOccurs="1" maxOccurs="unbounded" />
    </xs:complexType>
    </xs:element>
    <xs:group name="Group">
    <xs:choice>
    <xs:element ref="OptionOne" type="xs:string" />
    <xs:element ref="OptionTwo" />
    </xs:choice>
    </xs:group>
    <xs:element name="OptionOne">
    <xs:complexType>
    <xs:attribute name="name" type="xs:string" />
    <xs:attribute name="Type" type="xs:string" />
    </xs:complexType>
    </xs:element>
    <xs:element name="OptionTwo">
    <xs:complexType>
    <xs:attribute name="name" type="xs:string" />
    <xs:attribute name="Type" type="xs:string" />
    </xs:complexType>
    </xs:element>
    This allows XML like this
    <Parent>
    <OptionTwo ........ />
    <OptionOne ........ />
    <OptionTwo ........ />
    <OptionOne ........ />
    <OptionOne ........ />
    </Parent>
    HH

  • [[11g] many XMLSCHEMA for a given binary XML table

    Hi,
    --1-----------------------------------
    I cannot create a table associated with several xmlschemas.
    create table "VALIDATE_XML_SCHEMA" of XMLTYPE
    XMLTYPE STORE AS BASICFILE BINARY XML
    XMLSCHEMAS (XMLSCHEMA "http://www.binary.com/root.xsd" ELEMENT "ROOT",
    XMLSCHEMA "http://www.different.com/root.xsd" ELEMENT "ROOT") DISALLOW NONSCHEMA;
    ==> ORA 22853
    Does this syntax is wrong?
    --2----------------------------------
    What about add and remove an existing associated xmlschma ?
    ALTER table "VALIDATE_XML_SCHEMA"
    REMOVE XMLSCHEMAS (XMLSCHEMA "http://www.different.com/root.xsd" ELEMENT "ROOT");
    ALTER table "VALIDATE_XML_SCHEMA"
    ADD XMLSCHEMAS (XMLSCHEMA "http://www.different.com/root.xsd" ELEMENT "ROOT") DISALLOW NONSCHEMA;
    ---------------------------------

    OK, so here it goes ...
    TEST1.xsd
    <?xml version = "1.0" encoding = "UTF-8"?>
    <xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema"
          elementFormDefault = "qualified">
      <xsd:element name = "TEST1XML">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element ref = "ID"/>
            <xsd:element ref = "Description"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
      <xsd:element name = "ID">
        <xsd:simpleType>
          <xsd:restriction base = "xsd:string">
            <xsd:length value = "4"/>
          </xsd:restriction>
        </xsd:simpleType>
      </xsd:element>
      <xsd:element name = "Description">
        <xsd:simpleType>
          <xsd:restriction base = "xsd:string">
            <xsd:maxLength value = "35"/>
          </xsd:restriction>
        </xsd:simpleType>
      </xsd:element>
    </xsd:schema>TEST2.xsd
    <?xml version = "1.0" encoding = "UTF-8"?>
    <xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema"
          elementFormDefault = "qualified">
      <xsd:element name = "TEST2XML">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element ref = "ID"/>
            <xsd:element ref = "AccessedOn"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
      <xsd:element name = "ID">
        <xsd:simpleType>
          <xsd:restriction base = "xsd:string">
            <xsd:length value = "4"/>
          </xsd:restriction>
        </xsd:simpleType>
      </xsd:element>
      <xsd:element name = "AccessedOn" type="xsd:dateTime" />
    </xsd:schema>and the offending script
    SET TIMING ON;
    BEGIN
       DBMS_XMLSCHEMA.REGISTERSCHEMA(
         SCHEMAURL => 'http://localhost/xsd/TEST1.xsd',
         SCHEMADOC => BFILENAME('XML_FILES_DIR','TEST1.xsd'),
         LOCAL     => TRUE,
         GENTYPES  => FALSE,
         GENBEAN   => FALSE,
         GENTABLES => FALSE,
         FORCE     => FALSE,
         CSID      => NLS_CHARSET_ID('AL32UTF8'),
         OPTIONS   => DBMS_XMLSCHEMA.REGISTER_BINARYXML);
    END;
    BEGIN
       DBMS_XMLSCHEMA.REGISTERSCHEMA(
         SCHEMAURL => 'http://localhost/xsd/TEST2.xsd',
         SCHEMADOC => BFILENAME('XML_FILES_DIR','TEST2.xsd'),
         LOCAL     => TRUE,
         GENTYPES  => FALSE,
         GENBEAN   => FALSE,
         GENTABLES => FALSE,
         FORCE     => FALSE,
         CSID      => NLS_CHARSET_ID('AL32UTF8'),
         OPTIONS   => DBMS_XMLSCHEMA.REGISTER_BINARYXML);
    END;
    CREATE TABLE XML_TEST_TBL OF XMLTYPE
       XMLTYPE STORE AS SECUREFILE BINARY XML
       XMLSCHEMAS( XMLSCHEMA "http://localhost/xsd/TEST1.xsd" ELEMENT "TEST1XML",
                   XMLSCHEMA "http://localhost/xsd/TEST2.xsd" ELEMENT "TEST2XML")
       DISALLOW NONSCHEMA;
    COMMIT;After running the script, I get
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.45
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:01.47
    CREATE TABLE XML_TEST_TBL OF XMLTYPE
       XMLTYPE STORE AS SECUREFILE BINARY XML
       XMLSCHEMAS( XMLSCHEMA "http://localhost/xsd/TEST1.xsd" ELEMENT "TEST1XML",
                   XMLSCHEMA "http://localhost/xsd/TEST2.xsd" ELEMENT "TEST2XML")
       DISALLOW NONSCHEMA
    Error at line 28
    ORA-22853: invalid LOB storage option specificationSo, I am indeed hitting the issue !
    And to complement the posts made so far, all the other errors (ALTER TABLE syntax, multiple schemas for OBJECT RELATIONAL storage) mentioned still occur in 11.1.0.7 ....
    Maybe Mark can advise on how to proceed with this. I must say though that I am not too happy creating SRs... It might give a bad impression about me AND about the product and that would be unfair on both counts.
    Best Regards
    Philip

  • Creating XML Schema from tables With Constraints

    Greetings,
    I'd have an interesting question. I finally am getting familiar with the various kinds of xml solutions provided by the oracle database, but hey here I have another interesting question I can't seem to get into life. I'm currently generating XML Schemas (XSD) from the tables of my database. Its nice its cool however I'd need to have the table's constraints with the xsd:elements also. And heres my problem, I can't seem to insert the table constrains. I'll show you what I mean:
    <xsd:element name="MESSAGE_TABLE">
      <xsd:complexType>
        <xsd:sequence>
          <xsd:element name="MESSAGE_RECORD">
            <xsd:complexType>
              <xsd:all>
                <xsd:element name="ID" type="xsd:integer" minOccurs="1" />
                <xsd:element name="HEADER">
                  <xsd:simpleType>
                    <xsd:restriction base="xsd:string>
                      <xsd:maxLength value="255" />
                    </xsd:restriction>
                  </xsd:simpleType>
                </xsd:element>
              </xsd:all>
            </xsd:complexType>
          </xsd:element>
        </xsd:sequence>
      </xsd:complexType>
      <!-- I'd need some more things here like... -->
      <!-- Primary key(s) -->
      <xsd:key name="PK_ID_PRIM">
        <xsd:selector xpath="." />
        <xsd:field xpath="ID" />
      </xsd:key>
      <!-- Foreign key(s) -->
      <xsd:keyref name="FK_HEADER_FOREIGN" refer="PK_HEADER_ID">
        <xsd:selector xpath="HEADER" />
        <xsd:field xpath="ID" />
      </xsd:keyref>
      <!-- Unique constraint(s) -->
      <xsd:unique name="UQ_..." ... />
      </xsd:unique>
    </xsd:element>That would fit my business needs, however I may be so blind that I can't see the forest from the tree. Currently I got so far that:
              xmlElement
                  "xsd:schema",
                  xmlAttributes
                      'http://www.w3.org/2001/XMLSchema'      as "xmlns:xsd"
                  xmlElement
                    "xsd:element",
                    xmlAttributes
                      target_table                            as "name"
                    xmlElement               
                      "xsd:complexType",
                      xmlElement
                        "xsd:sequence",
                        xmlElement
                          "xsd:element",
                          xmlAttributes
                            target_table || '_RECORD'         as "name",
                            'unbounded'                       as "maxOccurs"
                          xmlElement
                            "xsd:complexType",
                            xmlElement
                              "xsd:sequence",
                                xmlAgg(ELEMENT)
                    xmlElement
                      "xsd:Key",
                )As you can see this won't be good since I have put a single xml element in there. I guess I'd need something more like an xmlAgg(CONSTRAINTS), however in that case I'm wondering how will the select's FROM part look like.
      FROM
        SELECT  table_name, internal_column_id,
                CASE
                  WHEN data_type IN ('VARCHAR2', 'CHAR')
                  THEN
                    xmlElement
                      "xsd:element",
                      xmlattributes
                        column_name as "name",
                        decode(NULLABLE, 'Y', 0, 1) as "minOccurs"
                      xmlElement
                        "xsd:simpleType",
                        xmlElement
                          "xsd:restriction",
                          xmlAttributes
                            'xsd:string' as "base"
                          xmlElement
                            "xsd:maxLength",
                            xmlAttributes
                              DATA_LENGTH as "value"
                  WHEN data_type = 'DATE'
                  THEN
                    xmlElement
                      "xsd:element",
                      xmlattributes
                        column_name as "name",
                        'xsd:date' as "type",
                        decode(NULLABLE, 'Y', 0, 1) as "minOccurs"
                  WHEN data_type = 'NUMBER'
                  THEN
                    xmlElement
                      "xsd:element",
                      xmlattributes
                        column_name as "name",
                        decode(DATA_SCALE, 0, 'xsd:integer', 'xsd:double') as "type",
                        decode(NULLABLE, 'Y', 0, 1) as "minOccurs"
                  ELSE
                    xmlElement
                      "xsd:element",
                      xmlattributes
                        column_name as "name",
                        'xsd:anySimpleType' as "type",
                        decode(NULLABLE, 'Y', 0, 1) as "minOccurs"
        end ELEMENT
        FROM user_tab_cols c
        WHERE TABLE_NAME = target_table
        ORDER BY internal_column_id
      GROUP BY TABLE_NAME;Thank you very much for all your help!
    Regards,
    Joey
    Edited by: Wrath#87 on 2012.09.05. 22:15

    Thanks for that, answer. That helped me a lot managing primary constraints. However I still have problems managing foreign keys. I come up with the following formula:
              xmlElement
                  "xsd:schema",
                  xmlAttributes
                      'http://www.w3.org/2001/XMLSchema'      as "xmlns:xsd"
                  xmlElement
                      "xsd:element",
                      xmlAttributes
                          upper(target_table) as "name"
                      xmlElement
                          "xsd:complexType",
                          xmlElement
                            "xsd:all",
                                xmlAgg(ELEMENT)
                          SELECT    xmlElement
                                      "xsd:key",
                                      xmlattributes
                                        uc.constraint_name as "name"
                                      xmlElement
                                        "xsd:selector",
                                        xmlattributes
                                          '.' as "xpath"
                                      xmlAgg
                                        xmlElement
                                          "xsd:field",
                                          xmlattributes
                                            ucc.column_name as "xpath"
                                        order by ucc.position
                          FROM      user_constraints uc
                                    JOIN      user_cons_columns ucc
                                    ON        ucc.constraint_name   =   uc.constraint_name
                          WHERE     uc.table_name                   =   upper(target_table)
                          AND       uc.constraint_type              =   'P'
                          GROUP BY  uc.constraint_name
                          SELECT    xmlElement
                                        "xsd:keyRef",
                                        xmlattributes
                                            a.constraint_name as "name"
                                        xmlElement
                                            "xsd:selector",
                                            xmlattributes
                                                c.table_name as "xpath"
                                        xmlAgg
                                            xmlElement
                                                "xsd:field",
                                                xmlattributes
                                                    d.column_name as "xpath"
                                            order by  c.table_name
                          FROM      all_constraints   a,
                                    all_cons_columns  b,
                                    all_constraints   c,
                                    all_cons_columns  d
                          WHERE     a.constraint_name   =   b.constraint_name
                          AND       a.constraint_name   =   c.r_constraint_name
                          AND       c.constraint_name   =   d.constraint_name
                          AND       a.table_name        =   upper(target_table)
              )This gives me the following error message: 00937. 00000 -  "not a single-group group function"

  • XML Schema Definition validation

    Hi all,
    I am trying to find the right way to get validation errors out of a xsd file - I found a couple of ways to do this but none of them seem to be the "right" way...
    (BTW, I am using Xerces 2.6.2)
    The first option was to validate the xsd against it's own xsd (http://www.w3.org/2001/XMLSchema.xsd) - but that's kind of stupid since the parser already knows what an xsd should look like and should be able to provide "smarter" errors besides mere structural ones.
    The second option is to set the xsd which I want to validate as the schema source to some pseudo xml which I parse only to get the errors in the xsd....
    something like this:
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    spf.setValidating(true);
    SAXParser sp = spf.newSAXParser();
    sp.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
    sp.setProperty(JAXP_SCHEMA_SOURCE, xsdForValidation);
    sp.parse(new InputSource(new StringReader("<root></root>")), new MyHandler());This is really stupid but as a result MyHandler gets notified about error in the xsd file, which is what I am interested in.... The problem is that I obviously get error reports for my pseudo xml..... How can I differentiate between the xsd errors and the xml errors I am reported about? there is nothing in the error data indicating if it came from the schema-source or the xml itself....
    What am I missing here? How can this reasonable need be so annoying to implement?

    Some of the Schema Editors validate a schema.
    Stylus Studio
    http://www.stylusstudio.com/
    http://www.tibco.com/software/business_integration/turboxml.jsp

  • Xml query hungs up with large xml response from utl_http request

    We are having very sensitive problem in Production environment with xmlquery.
    When receive a small or medium size xml, the query shown below works. But when the xml is large or very large its hung and slow down all the database.
    We are with Oracle 11gR2
    We are using clob to parse the response from the http request.
    What could be the problem or the solutions?. Please help. Its urgent...
    SELECT opciones_obj (x.strindice,
    x.nombrecompleto,
    x.nombre,
    x.strtipodato,
    x.codigoopcion,
    x.floatval,
    x.strtipo,
    x.strval)
    BULK COLLECT INTO t_opciones
    FROM XMLTABLE (
    xmlnamespaces (
    'http://schemas.xmlsoap.org/soap/envelope/' AS "env",
    'http://wsevaluarreglacondicioncomercial/' AS "ns0",
    'http://wsevaluarreglacondicioncomercial/types/' AS "ns1",
    'http://www.oracle.com/webservices/internal/literal' AS "ns2"),
    '/env:Envelope/env:Body/ns0:listarOpcionesAtributoEventoResponseElement/ns0:result/ns1:listaVariables/ns2:item/ns2:item'
    PASSING rsp_xml
    COLUMNS strindice VARCHAR2 (4000)
    PATH 'ns2:mapEntry[ns2:key="strIndice"]/ns2:value',
    nombrecompleto VARCHAR2 (4000)
    PATH 'ns2:mapEntry[ns2:key="nombreCompleto"]/ns2:value',
    nombre VARCHAR2 (4000)
    PATH 'ns2:mapEntry[ns2:key="nombre"]/ns2:value',
    strtipodato VARCHAR2 (4000)
    PATH 'ns2:mapEntry[ns2:key="strTipoDato"]/ns2:value',
    codigoopcion NUMBER
    PATH 'ns2:mapEntry[ns2:key="codigoOpcion"]/ns2:value',
    floatval FLOAT
    PATH 'ns2:mapEntry[ns2:key="floatVal"]/ns2:value',
    strtipo VARCHAR2 (4000)
    PATH 'ns2:mapEntry[ns2:key="strTipo"]/ns2:value',
    strval VARCHAR2 (4000)
    PATH 'ns2:mapEntry[ns2:key="strVal"]/ns2:value') x;

    What could be the problem or the solutions?1) Create an XMLType table (could be temporary) using binary XML storage :
    create table tmp_xml of xmltype
    xmltype store as securefile binary xml;2) In your procedure, load the XMLType containing the response (rsp_xml) into the table :
    insert into tmp_xml values (rsp_xml);3) Then, execute the query directly from the table :
    SELECT opciones_obj ( ... )
    BULK COLLECT INTO t_opciones
    FROM tmp_xml t
       , XMLTABLE (
             xmlnamespaces ( ... ),
             '/env:Envelope/env:Body/...'
             PASSING t.object_value
             COLUMNS ...4) At the end of the procedure, delete (or truncate) the table or simply let the table delete itself when the session ends (in case you created it TEMPORARY)

  • XSD Validation with ABAP XML Parser?

    Hello there,
    i'm loading xml files into a R/3 System. This all works fine with the standard XML Parser.
    The XML Files are based on a .xsd structure that is assigned to each file with a external link.
    To be sure that the xml document conforms to this .xsd structure i would like to check against it.
    For that i would like to hold a .xsd structure string in my abap programm.
    How can this be accomplished? Is this possible anyway?
    Greetings and many thanks.
    Kay

    check out the class
    CL_XML_SCHEMA
    Regards
    Raja

  • How to create XML from relational tables based on an XML Schema ?

    There is no automated way in Oracle XML DB to define an automatic mapping between a set of columns in some existing relational tables and the elements and attributres defined by an XML Schema.
    However it is easy solve this problem by using the SQL/XML operators (XMLAGG, XMLELEMENT, XMLFOREST, XMLATTRIBUTES, etc) to generate XML documents that are compliant with an XML Schema directly from a SQL statement.
    If the XML Schema is registered with Oracle XML DB and the appropraite Schema Location information is added into the generated document using XMLAttributes then it becomes very easy to ensure that the generated documents are valid.
    The following example show an easy way to do this by creating an XML View that contains the documents to be validated.
    SQL> drop table PURCHASEORDER_LINEITEM
      2  /
    Table dropped.
    SQL> drop table PURCHASEORDER_REJECTION
      2  /
    Table dropped.
    SQL> drop table PURCHASEORDER_SHIPPING
      2  /
    Table dropped.
    SQL> drop TABLE PURCHASEORDER_ACTION
      2  /
    Table dropped.
    SQL> drop TABLE PURCHASEORDER_TABLE
      2  /
    Table dropped.
    SQL> create table PURCHASEORDER_TABLE
      2  (
      3   REFERENCE                                          VARCHAR2(28),
      4   PRIMARY KEY ("REFERENCE"),
      5   REQUESTER                                          VARCHAR2(48),
      6   USERID                                             VARCHAR2(32),
      7   COSTCENTER                                         VARCHAR2(3),
      8   SPECIALINSTRUCTIONS                                VARCHAR2(2048)
      9  )
    10  /
    Table created.
    SQL> create table PURCHASEORDER_ACTION
      2  (
      3   REFERENCE,
      4   FOREIGN KEY ("REFERENCE")                          REFERENCES "PURCHASEORDER_TABLE" ("REFERENCE") ON DELETE CASCADE,
      5   ACTIONEDBY                                         VARCHAR2(32),
      6   DATEACTIONED                                       DATE
      7  )
      8  /
    Table created.
    SQL> create table PURCHASEORDER_SHIPPING
      2  (
      3   REFERENCE,
      4   FOREIGN KEY ("REFERENCE")                          REFERENCES "PURCHASEORDER_TABLE" ("REFERENCE") ON DELETE CASCADE,
      5   PRIMARY KEY ("REFERENCE"),
      6   SHIPTONAME                                         VARCHAR2(48),
      7   ADDRESS                                            VARCHAR2(512),
      8   PHONE                                              VARCHAR2(32)
      9  )
    10  /
    Table created.
    SQL> create table PURCHASEORDER_REJECTION
      2  (
      3   REFERENCE,
      4   FOREIGN KEY ("REFERENCE")                          REFERENCES "PURCHASEORDER_TABLE" ("REFERENCE") ON DELETE CASCADE,
      5   PRIMARY KEY ("REFERENCE"),
      6   REJECTEDBY                                         VARCHAR2(32),
      7   DATEREJECTED                                       DATE,
      8   COMMENTS                                           VARCHAR2(2048)
      9  )
    10  /
    Table created.
    SQL> create table PURCHASEORDER_LINEITEM
      2  (
      3   REFERENCE,
      4   FOREIGN KEY ("REFERENCE")                          REFERENCES "PURCHASEORDER_TABLE" ("REFERENCE") ON DELETE CASCADE,
      5   LINENO                                             NUMBER(10),
      6   PRIMARY KEY ("REFERENCE","LINENO"),
      7   UPC                                                   VARCHAR2(14),
      8   DESCRIPTION                                        VARCHAR2(128),
      9   QUANTITY                                           NUMBER(10),
    10   UNITPRICE                                          NUMBER(12,2)
    11  )
    12  /
    Table created.
    SQL> insert into PURCHASEORDER_TABLE values ('SMCCAIN-20030109123335470PDT','Samuel B. McCain','SMCCAIN','A10','Courier')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_ACTION values ('SMCCAIN-20030109123335470PDT','SVOLLMAN',NULL)
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_SHIPPING values ('SMCCAIN-20030109123335470PDT','Samuel B. McCain','800 Bridge Parkway,Redwood Shores,CA,9406
    5,USA','650 506 7800')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_REJECTION values ('SMCCAIN-20030109123335470PDT',null,null,null)
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','1','715515010320','Life of Brian - Monty Python''s','2','39.
    95')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','2','37429145227','The Night Porter','2','29.95')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','3','37429128121','Oliver Twist','1','39.95')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','4','715515012720','Notorious','4','39.95')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','5','715515012928','In the Mood for Love','3','39.95')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','6','37429130926','Alphaville','2','29.95')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','7','37429166529','General Idi Amin Dada','4','29.95')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','8','715515012928','In the Mood for Love','3','39.95')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','9','715515009423','Flesh for Frankenstein','3','39.95')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','10','715515008976','The Killer','1','39.95')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','11','37429167922','Ballad of a Soldier','2','29.95')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','12','37429158623','Ordet','2','0')
      2  /
    1 row created.
    SQL> var schemaPath varchar2(256)
    SQL> --
    SQL> begin
      2    :schemaURL := 'http://xfiles:8080/home/SCOTT/poSource/xsd/purchaseOrder.xsd';
      3    :schemaPath := '/public/purchaseOrder.xsd';
      4  end;
      5  /
    PL/SQL procedure successfully completed.
    SQL> call dbms_xmlSchema.deleteSchema(:schemaURL,4)
      2  /
    Call completed.
    SQL> declare
      2    res boolean;
      3    xmlSchema xmlType := xmlType(
      4  '<!-- edited with XML Spy v4.0 U (http://www.xmlspy.com) by Mark (Drake) -->
      5  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.com/xdb" version="1.0" xdb:storeVarrayAsTable="tr
    ue">
      6          <xs:element name="PurchaseOrder" type="PurchaseOrderType" xdb:defaultTable="PURCHASEORDER"/>
      7          <xs:complexType name="PurchaseOrderType" xdb:SQLType="PURCHASEORDER_T" xdb:maintainDOM="false">
      8                  <xs:sequence>
      9                          <xs:element name="Reference" type="ReferenceType" xdb:SQLName="REFERENCE"/>
    10                          <xs:element name="Actions" type="ActionsType" xdb:SQLName="ACTIONS"/>
    11                          <xs:element name="Reject" type="RejectionType" minOccurs="0" xdb:SQLName="REJECTION"/>
    12                          <xs:element name="Requestor" type="RequestorType" xdb:SQLName="REQUESTOR"/>
    13                          <xs:element name="User" type="UserType" xdb:SQLName="USERID"/>
    14                          <xs:element name="CostCenter" type="CostCenterType" xdb:SQLName="COST_CENTER"/>
    15                          <xs:element name="ShippingInstructions" type="ShippingInstructionsType" xdb:SQLName="SHIPPING_INSTRUCTIONS"/>
    16                          <xs:element name="SpecialInstructions" type="SpecialInstructionsType" xdb:SQLName="SPECIAL_INSTRUCTIONS"/>
    17                          <xs:element name="LineItems" type="LineItemsType" xdb:SQLName="LINEITEMS"/>
    18                  </xs:sequence>
    19          </xs:complexType>
    20          <xs:complexType name="LineItemsType" xdb:SQLType="LINEITEMS_T" xdb:maintainDOM="false">
    21                  <xs:sequence>
    22                          <xs:element name="LineItem" type="LineItemType" maxOccurs="unbounded" xdb:SQLName="LINEITEM" xdb:SQLCollType="L
    INEITEM_V"/>
    23                  </xs:sequence>
    24          </xs:complexType>
    25          <xs:complexType name="LineItemType" xdb:SQLType="LINEITEM_T" xdb:maintainDOM="false">
    26                  <xs:sequence>
    27                          <xs:element name="Description" type="DescriptionType" xdb:SQLName="DESRIPTION"/>
    28                          <xs:element name="Part" type="PartType" xdb:SQLName="PART"/>
    29                  </xs:sequence>
    30                  <xs:attribute name="ItemNumber" type="xs:integer" xdb:SQLName="ITEMNUMBER" xdb:SQLType="NUMBER"/>
    31          </xs:complexType>
    32          <xs:complexType name="PartType" xdb:SQLType="PART_T" xdb:maintainDOM="false">
    33                  <xs:attribute name="Id" xdb:SQLName="PART_NUMBER" xdb:SQLType="VARCHAR2">
    34                          <xs:simpleType>
    35                                  <xs:restriction base="xs:string">
    36                                          <xs:minLength value="10"/>
    37                                          <xs:maxLength value="14"/>
    38                                  </xs:restriction>
    39                          </xs:simpleType>
    40                  </xs:attribute>
    41                  <xs:attribute name="Quantity" type="moneyType" xdb:SQLName="QUANTITY"/>
    42                  <xs:attribute name="UnitPrice" type="quantityType" xdb:SQLName="UNITPRICE"/>
    43          </xs:complexType>
    44          <xs:simpleType name="ReferenceType">
    45                  <xs:restriction base="xs:string">
    46                          <xs:minLength value="18"/>
    47                          <xs:maxLength value="30"/>
    48                  </xs:restriction>
    49          </xs:simpleType>
    50          <xs:complexType name="ActionsType" xdb:SQLType="ACTIONS_T" xdb:maintainDOM="false">
    51                  <xs:sequence>
    52                          <xs:element name="Action" maxOccurs="4" xdb:SQLName="ACTION" xdb:SQLCollType="ACTION_V">
    53                                  <xs:complexType xdb:SQLType="ACTION_T" xdb:maintainDOM="false">
    54                                          <xs:sequence>
    55                                                  <xs:element name="User" type="UserType" xdb:SQLName="ACTIONED_BY"/>
    56                                                  <xs:element name="Date" type="DateType" minOccurs="0" xdb:SQLName="DATE_ACTIONED"/>
    57                                          </xs:sequence>
    58                                  </xs:complexType>
    59                          </xs:element>
    60                  </xs:sequence>
    61          </xs:complexType>
    62          <xs:complexType name="RejectionType" xdb:SQLType="REJECTION_T" xdb:maintainDOM="false">
    63                  <xs:all>
    64                          <xs:element name="User" type="UserType" minOccurs="0" xdb:SQLName="REJECTED_BY"/>
    65                          <xs:element name="Date" type="DateType" minOccurs="0" xdb:SQLName="DATE_REJECTED"/>
    66                          <xs:element name="Comments" type="CommentsType" minOccurs="0" xdb:SQLName="REASON_REJECTED"/>
    67                  </xs:all>
    68          </xs:complexType>
    69          <xs:complexType name="ShippingInstructionsType" xdb:SQLType="SHIPPING_INSTRUCTIONS_T" xdb:maintainDOM="false">
    70                  <xs:sequence>
    71                          <xs:element name="name" type="NameType" minOccurs="0" xdb:SQLName="SHIP_TO_NAME"/>
    72                          <xs:element name="address" type="AddressType" minOccurs="0" xdb:SQLName="SHIP_TO_ADDRESS"/>
    73                          <xs:element name="telephone" type="TelephoneType" minOccurs="0" xdb:SQLName="SHIP_TO_PHONE"/>
    74                  </xs:sequence>
    75          </xs:complexType>
    76          <xs:simpleType name="moneyType">
    77                  <xs:restriction base="xs:decimal">
    78                          <xs:fractionDigits value="2"/>
    79                          <xs:totalDigits value="12"/>
    80                  </xs:restriction>
    81          </xs:simpleType>
    82          <xs:simpleType name="quantityType">
    83                  <xs:restriction base="xs:decimal">
    84                          <xs:fractionDigits value="4"/>
    85                          <xs:totalDigits value="8"/>
    86                  </xs:restriction>
    87          </xs:simpleType>
    88          <xs:simpleType name="UserType">
    89                  <xs:restriction base="xs:string">
    90                          <xs:minLength value="1"/>
    91                          <xs:maxLength value="10"/>
    92                  </xs:restriction>
    93          </xs:simpleType>
    94          <xs:simpleType name="RequestorType">
    95                  <xs:restriction base="xs:string">
    96                          <xs:minLength value="0"/>
    97                          <xs:maxLength value="128"/>
    98                  </xs:restriction>
    99          </xs:simpleType>
    100          <xs:simpleType name="CostCenterType">
    101                  <xs:restriction base="xs:string">
    102                          <xs:minLength value="1"/>
    103                          <xs:maxLength value="4"/>
    104                  </xs:restriction>
    105          </xs:simpleType>
    106          <xs:simpleType name="VendorType">
    107                  <xs:restriction base="xs:string">
    108                          <xs:minLength value="0"/>
    109                          <xs:maxLength value="20"/>
    110                  </xs:restriction>
    111          </xs:simpleType>
    112          <xs:simpleType name="PurchaseOrderNumberType">
    113                  <xs:restriction base="xs:integer"/>
    114          </xs:simpleType>
    115          <xs:simpleType name="SpecialInstructionsType">
    116                  <xs:restriction base="xs:string">
    117                          <xs:minLength value="0"/>
    118                          <xs:maxLength value="2048"/>
    119                  </xs:restriction>
    120          </xs:simpleType>
    121          <xs:simpleType name="NameType">
    122                  <xs:restriction base="xs:string">
    123                          <xs:minLength value="1"/>
    124                          <xs:maxLength value="20"/>
    125                  </xs:restriction>
    126          </xs:simpleType>
    127          <xs:simpleType name="AddressType">
    128                  <xs:restriction base="xs:string">
    129                          <xs:minLength value="1"/>
    130                          <xs:maxLength value="256"/>
    131                  </xs:restriction>
    132          </xs:simpleType>
    133          <xs:simpleType name="TelephoneType">
    134                  <xs:restriction base="xs:string">
    135                          <xs:minLength value="1"/>
    136                          <xs:maxLength value="24"/>
    137                  </xs:restriction>
    138          </xs:simpleType>
    139          <xs:simpleType name="DateType">
    140                  <xs:restriction base="xs:date"/>
    141          </xs:simpleType>
    142          <xs:simpleType name="CommentsType">
    143                  <xs:restriction base="xs:string">
    144                          <xs:minLength value="1"/>
    145                          <xs:maxLength value="2048"/>
    146                  </xs:restriction>
    147          </xs:simpleType>
    148          <xs:simpleType name="DescriptionType">
    149                  <xs:restriction base="xs:string">
    150                          <xs:minLength value="1"/>
    151                          <xs:maxLength value="256"/>
    152                  </xs:restriction>
    153          </xs:simpleType>
    154  </xs:schema>
    155  ');
    156  begin
    157    if (dbms_xdb.existsResource(:schemaPath)) then
    158      dbms_xdb.deleteResource(:schemaPath);
    159    end if;
    160    res := dbms_xdb.createResource(:schemaPath,xmlSchema);
    161  end;
    162  /
    PL/SQL procedure successfully completed.
    SQL> begin
      2    dbms_xmlschema.registerSchema
      3    (
      4      :schemaURL,
      5      xdbURIType(:schemaPath).getClob(),
      6      TRUE,TRUE,FALSE,FALSE
      7    );
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    SQL> create or replace view PURCHASEORDER_XML
      2  of xmltype
      3  xmlSCHEMA "http://xfiles:8080/home/SCOTT/poSource/xsd/purchaseOrder.xsd" Element "PurchaseOrder"
      4  with object id
      5  (
      6    substr(extractValue(object_value,'/PurchaseOrder/Reference'),1,32)
      7  )
      8  as
      9    select xmlElement
    10           (
    11             "PurchaseOrder",
    12             xmlAttributes
    13             (
    14               'http://xfiles:8080/home/SCOTT/poSource/xsd/purchaseOrder.xsd' as "xsi:noNamespaceSchemaLocation",
    15               'http://www.w3.org/2001/XMLSchema-instance' as "xmlns:xsi"
    16             ),
    17             xmlElement("Reference",p.REFERENCE),
    18             xmlElement
    19             (
    20               "Actions",
    21               ( select xmlAgg
    22                        (
    23                          xmlElement
    24                          (
    25                            "Action",
    26                            xmlElement("User",ACTIONEDBY),
    27                            case
    28                              when DATEACTIONED is not null
    29                              then xmlElement("Date",DATEACTIONED)
    30                            end
    31                          )
    32                        )
    33                   from PURCHASEORDER_ACTION a
    34                  where a.REFERENCE = p.REFERENCE
    35               )
    36             ),
    37             xmlElement
    38             (
    39               "Reject",
    40                  xmlForest
    41                  (
    42                    REJECTEDBY as "User",
    43                 DATEREJECTED as "Date",
    44                    COMMENTS as "Comments"
    45                  )
    46             ),
    47             xmlElement("Requestor",REQUESTER),
    48             xmlElement("User",USERID),
    49             xmlElement("CostCenter",COSTCENTER),
    50             xmlElement
    51             (
    52               "ShippingInstructions",
    53               xmlElement("name",SHIPTONAME),
    54               xmlElement("address",ADDRESS),
    55               xmlElement("telephone",PHONE)
    56             ),
    57             xmlElement("SpecialInstructions",SPECIALINSTRUCTIONS),
    58             xmlElement
    59             (
    60               "LineItems",
    61               ( select xmlAgg
    62                        (
    63                          xmlElement
    64                          (
    65                            "LineItem",
    66                            xmlAttributes(LINENO as "ItemNumber"),
    67                            xmlElement("Description",DESCRIPTION),
    68                            xmlElement
    69                            (
    70                              "Part",
    71                              xmlAttributes
    72                              (
    73                                UPC       as "Id",
    74                                QUANTITY  as "Quantity",
    75                                UNITPRICE as "UnitPrice"
    76                              )
    77                            )
    78                          )
    79                        )
    80                    from PURCHASEORDER_LINEITEM l
    81                   where l.REFERENCE = p.REFERENCE
    82               )
    83             )
    84           )
    85      from PURCHASEORDER_TABLE p, PURCHASEORDER_REJECTION r, PURCHASEORDER_SHIPPING s
    86     where r.REFERENCE = p.REFERENCE
    87       and s.REFERENCE = p.REFERENCE
    88  /
    View created.
    SQL> set long 10000 pages 0 lines 140
    SQL> --
    SQL> select x.object_value.extract('/*')
      2    from PURCHASEORDER_XML x
      3  /
    <PurchaseOrder xsi:noNamespaceSchemaLocation="http://xfiles:8080/home/SCOTT/poSource/xsd/purchaseOrder.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <Reference>SMCCAIN-20030109123335470PDT</Reference>
      <Actions>
        <Action>
          <User>SVOLLMAN</User>
        </Action>
      </Actions>
      <Reject/>
      <Requestor>Samuel B. McCain</Requestor>
      <User>SMCCAIN</User>
      <CostCenter>A10</CostCenter>
      <ShippingInstructions>
        <name>Samuel B. McCain</name>
        <address>800 Bridge Parkway,Redwood Shores,CA,94065,USA</address>
        <telephone>650 506 7800</telephone>
      </ShippingInstructions>
      <SpecialInstructions>Courier</SpecialInstructions>
      <LineItems>
        <LineItem ItemNumber="1">
          <Description>Life of Brian - Monty Python&apos;s</Description>
          <Part Id="715515010320" Quantity="2" UnitPrice="39.95"/>
        </LineItem>
        <LineItem ItemNumber="2">
          <Description>The Night Porter</Description>
          <Part Id="37429145227" Quantity="2" UnitPrice="29.95"/>
        </LineItem>
        <LineItem ItemNumber="3">
          <Description>Oliver Twist</Description>
          <Part Id="37429128121" Quantity="1" UnitPrice="39.95"/>
        </LineItem>
        <LineItem ItemNumber="4">
          <Description>Notorious</Description>
          <Part Id="715515012720" Quantity="4" UnitPrice="39.95"/>
        </LineItem>
        <LineItem ItemNumber="5">
          <Description>In the Mood for Love</Description>
          <Part Id="715515012928" Quantity="3" UnitPrice="39.95"/>
        </LineItem>
        <LineItem ItemNumber="6">
          <Description>Alphaville</Description>
          <Part Id="37429130926" Quantity="2" UnitPrice="29.95"/>
        </LineItem>
        <LineItem ItemNumber="7">
          <Description>General Idi Amin Dada</Description>
          <Part Id="37429166529" Quantity="4" UnitPrice="29.95"/>
        </LineItem>
        <LineItem ItemNumber="8">
          <Description>In the Mood for Love</Description>
          <Part Id="715515012928" Quantity="3" UnitPrice="39.95"/>
        </LineItem>
        <LineItem ItemNumber="9">
          <Description>Flesh for Frankenstein</Description>
          <Part Id="715515009423" Quantity="3" UnitPrice="39.95"/>
        </LineItem>
        <LineItem ItemNumber="10">
          <Description>The Killer</Description>
          <Part Id="715515008976" Quantity="1" UnitPrice="39.95"/>
        </LineItem>
        <LineItem ItemNumber="11">
          <Description>Ballad of a Soldier</Description>
          <Part Id="37429167922" Quantity="2" UnitPrice="29.95"/>
        </LineItem>
        <LineItem ItemNumber="12">
          <Description>Ordet</Description>
          <Part Id="37429158623" Quantity="2" UnitPrice="0"/>
        </LineItem>
      </LineItems>
    </PurchaseOrder>
    SQL> begin
      2    for x in (select object_value from PURCHASEORDER_XML) loop
      3      x.object_value.schemaValidate();
      4    end loop;
      5  end;
      6  /
    PL/SQL procedure successfully completed.
    SQL>

    There is no automated way in Oracle XML DB to define an automatic mapping between a set of columns in some existing relational tables and the elements and attributres defined by an XML Schema.
    However it is easy solve this problem by using the SQL/XML operators (XMLAGG, XMLELEMENT, XMLFOREST, XMLATTRIBUTES, etc) to generate XML documents that are compliant with an XML Schema directly from a SQL statement.
    If the XML Schema is registered with Oracle XML DB and the appropraite Schema Location information is added into the generated document using XMLAttributes then it becomes very easy to ensure that the generated documents are valid.
    The following example show an easy way to do this by creating an XML View that contains the documents to be validated.
    SQL> drop table PURCHASEORDER_LINEITEM
      2  /
    Table dropped.
    SQL> drop table PURCHASEORDER_REJECTION
      2  /
    Table dropped.
    SQL> drop table PURCHASEORDER_SHIPPING
      2  /
    Table dropped.
    SQL> drop TABLE PURCHASEORDER_ACTION
      2  /
    Table dropped.
    SQL> drop TABLE PURCHASEORDER_TABLE
      2  /
    Table dropped.
    SQL> create table PURCHASEORDER_TABLE
      2  (
      3   REFERENCE                                          VARCHAR2(28),
      4   PRIMARY KEY ("REFERENCE"),
      5   REQUESTER                                          VARCHAR2(48),
      6   USERID                                             VARCHAR2(32),
      7   COSTCENTER                                         VARCHAR2(3),
      8   SPECIALINSTRUCTIONS                                VARCHAR2(2048)
      9  )
    10  /
    Table created.
    SQL> create table PURCHASEORDER_ACTION
      2  (
      3   REFERENCE,
      4   FOREIGN KEY ("REFERENCE")                          REFERENCES "PURCHASEORDER_TABLE" ("REFERENCE") ON DELETE CASCADE,
      5   ACTIONEDBY                                         VARCHAR2(32),
      6   DATEACTIONED                                       DATE
      7  )
      8  /
    Table created.
    SQL> create table PURCHASEORDER_SHIPPING
      2  (
      3   REFERENCE,
      4   FOREIGN KEY ("REFERENCE")                          REFERENCES "PURCHASEORDER_TABLE" ("REFERENCE") ON DELETE CASCADE,
      5   PRIMARY KEY ("REFERENCE"),
      6   SHIPTONAME                                         VARCHAR2(48),
      7   ADDRESS                                            VARCHAR2(512),
      8   PHONE                                              VARCHAR2(32)
      9  )
    10  /
    Table created.
    SQL> create table PURCHASEORDER_REJECTION
      2  (
      3   REFERENCE,
      4   FOREIGN KEY ("REFERENCE")                          REFERENCES "PURCHASEORDER_TABLE" ("REFERENCE") ON DELETE CASCADE,
      5   PRIMARY KEY ("REFERENCE"),
      6   REJECTEDBY                                         VARCHAR2(32),
      7   DATEREJECTED                                       DATE,
      8   COMMENTS                                           VARCHAR2(2048)
      9  )
    10  /
    Table created.
    SQL> create table PURCHASEORDER_LINEITEM
      2  (
      3   REFERENCE,
      4   FOREIGN KEY ("REFERENCE")                          REFERENCES "PURCHASEORDER_TABLE" ("REFERENCE") ON DELETE CASCADE,
      5   LINENO                                             NUMBER(10),
      6   PRIMARY KEY ("REFERENCE","LINENO"),
      7   UPC                                                   VARCHAR2(14),
      8   DESCRIPTION                                        VARCHAR2(128),
      9   QUANTITY                                           NUMBER(10),
    10   UNITPRICE                                          NUMBER(12,2)
    11  )
    12  /
    Table created.
    SQL> insert into PURCHASEORDER_TABLE values ('SMCCAIN-20030109123335470PDT','Samuel B. McCain','SMCCAIN','A10','Courier')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_ACTION values ('SMCCAIN-20030109123335470PDT','SVOLLMAN',NULL)
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_SHIPPING values ('SMCCAIN-20030109123335470PDT','Samuel B. McCain','800 Bridge Parkway,Redwood Shores,CA,9406
    5,USA','650 506 7800')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_REJECTION values ('SMCCAIN-20030109123335470PDT',null,null,null)
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','1','715515010320','Life of Brian - Monty Python''s','2','39.
    95')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','2','37429145227','The Night Porter','2','29.95')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','3','37429128121','Oliver Twist','1','39.95')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','4','715515012720','Notorious','4','39.95')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','5','715515012928','In the Mood for Love','3','39.95')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','6','37429130926','Alphaville','2','29.95')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','7','37429166529','General Idi Amin Dada','4','29.95')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','8','715515012928','In the Mood for Love','3','39.95')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','9','715515009423','Flesh for Frankenstein','3','39.95')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','10','715515008976','The Killer','1','39.95')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','11','37429167922','Ballad of a Soldier','2','29.95')
      2  /
    1 row created.
    SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','12','37429158623','Ordet','2','0')
      2  /
    1 row created.
    SQL> var schemaPath varchar2(256)
    SQL> --
    SQL> begin
      2    :schemaURL := 'http://xfiles:8080/home/SCOTT/poSource/xsd/purchaseOrder.xsd';
      3    :schemaPath := '/public/purchaseOrder.xsd';
      4  end;
      5  /
    PL/SQL procedure successfully completed.
    SQL> call dbms_xmlSchema.deleteSchema(:schemaURL,4)
      2  /
    Call completed.
    SQL> declare
      2    res boolean;
      3    xmlSchema xmlType := xmlType(
      4  '<!-- edited with XML Spy v4.0 U (http://www.xmlspy.com) by Mark (Drake) -->
      5  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.com/xdb" version="1.0" xdb:storeVarrayAsTable="tr
    ue">
      6          <xs:element name="PurchaseOrder" type="PurchaseOrderType" xdb:defaultTable="PURCHASEORDER"/>
      7          <xs:complexType name="PurchaseOrderType" xdb:SQLType="PURCHASEORDER_T" xdb:maintainDOM="false">
      8                  <xs:sequence>
      9                          <xs:element name="Reference" type="ReferenceType" xdb:SQLName="REFERENCE"/>
    10                          <xs:element name="Actions" type="ActionsType" xdb:SQLName="ACTIONS"/>
    11                          <xs:element name="Reject" type="RejectionType" minOccurs="0" xdb:SQLName="REJECTION"/>
    12                          <xs:element name="Requestor" type="RequestorType" xdb:SQLName="REQUESTOR"/>
    13                          <xs:element name="User" type="UserType" xdb:SQLName="USERID"/>
    14                          <xs:element name="CostCenter" type="CostCenterType" xdb:SQLName="COST_CENTER"/>
    15                          <xs:element name="ShippingInstructions" type="ShippingInstructionsType" xdb:SQLName="SHIPPING_INSTRUCTIONS"/>
    16                          <xs:element name="SpecialInstructions" type="SpecialInstructionsType" xdb:SQLName="SPECIAL_INSTRUCTIONS"/>
    17                          <xs:element name="LineItems" type="LineItemsType" xdb:SQLName="LINEITEMS"/>
    18                  </xs:sequence>
    19          </xs:complexType>
    20          <xs:complexType name="LineItemsType" xdb:SQLType="LINEITEMS_T" xdb:maintainDOM="false">
    21                  <xs:sequence>
    22                          <xs:element name="LineItem" type="LineItemType" maxOccurs="unbounded" xdb:SQLName="LINEITEM" xdb:SQLCollType="L
    INEITEM_V"/>
    23                  </xs:sequence>
    24          </xs:complexType>
    25          <xs:complexType name="LineItemType" xdb:SQLType="LINEITEM_T" xdb:maintainDOM="false">
    26                  <xs:sequence>
    27                          <xs:element name="Description" type="DescriptionType" xdb:SQLName="DESRIPTION"/>
    28                          <xs:element name="Part" type="PartType" xdb:SQLName="PART"/>
    29                  </xs:sequence>
    30                  <xs:attribute name="ItemNumber" type="xs:integer" xdb:SQLName="ITEMNUMBER" xdb:SQLType="NUMBER"/>
    31          </xs:complexType>
    32          <xs:complexType name="PartType" xdb:SQLType="PART_T" xdb:maintainDOM="false">
    33                  <xs:attribute name="Id" xdb:SQLName="PART_NUMBER" xdb:SQLType="VARCHAR2">
    34                          <xs:simpleType>
    35                                  <xs:restriction base="xs:string">
    36                                          <xs:minLength value="10"/>
    37                                          <xs:maxLength value="14"/>
    38                                  </xs:restriction>
    39                          </xs:simpleType>
    40                  </xs:attribute>
    41                  <xs:attribute name="Quantity" type="moneyType" xdb:SQLName="QUANTITY"/>
    42                  <xs:attribute name="UnitPrice" type="quantityType" xdb:SQLName="UNITPRICE"/>
    43          </xs:complexType>
    44          <xs:simpleType name="ReferenceType">
    45                  <xs:restriction base="xs:string">
    46                          <xs:minLength value="18"/>
    47                          <xs:maxLength value="30"/>
    48                  </xs:restriction>
    49          </xs:simpleType>
    50          <xs:complexType name="ActionsType" xdb:SQLType="ACTIONS_T" xdb:maintainDOM="false">
    51                  <xs:sequence>
    52                          <xs:element name="Action" maxOccurs="4" xdb:SQLName="ACTION" xdb:SQLCollType="ACTION_V">
    53                                  <xs:complexType xdb:SQLType="ACTION_T" xdb:maintainDOM="false">
    54                                          <xs:sequence>
    55                                                  <xs:element name="User" type="UserType" xdb:SQLName="ACTIONED_BY"/>
    56                                                  <xs:element name="Date" type="DateType" minOccurs="0" xdb:SQLName="DATE_ACTIONED"/>
    57                                          </xs:sequence>
    58                                  </xs:complexType>
    59                          </xs:element>
    60                  </xs:sequence>
    61          </xs:complexType>
    62          <xs:complexType name="RejectionType" xdb:SQLType="REJECTION_T" xdb:maintainDOM="false">
    63                  <xs:all>
    64                          <xs:element name="User" type="UserType" minOccurs="0" xdb:SQLName="REJECTED_BY"/>
    65                          <xs:element name="Date" type="DateType" minOccurs="0" xdb:SQLName="DATE_REJECTED"/>
    66                          <xs:element name="Comments" type="CommentsType" minOccurs="0" xdb:SQLName="REASON_REJECTED"/>
    67                  </xs:all>
    68          </xs:complexType>
    69          <xs:complexType name="ShippingInstructionsType" xdb:SQLType="SHIPPING_INSTRUCTIONS_T" xdb:maintainDOM="false">
    70                  <xs:sequence>
    71                          <xs:element name="name" type="NameType" minOccurs="0" xdb:SQLName="SHIP_TO_NAME"/>
    72                          <xs:element name="address" type="AddressType" minOccurs="0" xdb:SQLName="SHIP_TO_ADDRESS"/>
    73                          <xs:element name="telephone" type="TelephoneType" minOccurs="0" xdb:SQLName="SHIP_TO_PHONE"/>
    74                  </xs:sequence>
    75          </xs:complexType>
    76          <xs:simpleType name="moneyType">
    77                  <xs:restriction base="xs:decimal">
    78                          <xs:fractionDigits value="2"/>
    79                          <xs:totalDigits value="12"/>
    80                  </xs:restriction>
    81          </xs:simpleType>
    82          <xs:simpleType name="quantityType">
    83                  <xs:restriction base="xs:decimal">
    84                          <xs:fractionDigits value="4"/>
    85                          <xs:totalDigits value="8"/>
    86                  </xs:restriction>
    87          </xs:simpleType>
    88          <xs:simpleType name="UserType">
    89                  <xs:restriction base="xs:string">
    90                          <xs:minLength value="1"/>
    91                          <xs:maxLength value="10"/>
    92                  </xs:restriction>
    93          </xs:simpleType>
    94          <xs:simpleType name="RequestorType">
    95                  <xs:restriction base="xs:string">
    96                          <xs:minLength value="0"/>
    97                          <xs:maxLength value="128"/>
    98                  </xs:restriction>
    99          </xs:simpleType>
    100          <xs:simpleType name="CostCenterType">
    101                  <xs:restriction base="xs:string">
    102                          <xs:minLength value="1"/>
    103                          <xs:maxLength value="4"/>
    104                  </xs:restriction>
    105          </xs:simpleType>
    106          <xs:simpleType name="VendorType">
    107                  <xs:restriction base="xs:string">
    108                          <xs:minLength value="0"/>
    109                          <xs:maxLength value="20"/>
    110                  </xs:restriction>
    111          </xs:simpleType>
    112          <xs:simpleType name="PurchaseOrderNumberType">
    113                  <xs:restriction base="xs:integer"/>
    114          </xs:simpleType>
    115          <xs:simpleType name="SpecialInstructionsType">
    116                  <xs:restriction base="xs:string">
    117                          <xs:minLength value="0"/>
    118                          <xs:maxLength value="2048"/>
    119                  </xs:restriction>
    120          </xs:simpleType>
    121          <xs:simpleType name="NameType">
    122                  <xs:restriction base="xs:string">
    123                          <xs:minLength value="1"/>
    124                          <xs:maxLength value="20"/>
    125                  </xs:restriction>
    126          </xs:simpleType>
    127          <xs:simpleType name="AddressType">
    128                  <xs:restriction base="xs:string">
    129                          <xs:minLength value="1"/>
    130                          <xs:maxLength value="256"/>
    131                  </xs:restriction>
    132          </xs:simpleType>
    133          <xs:simpleType name="TelephoneType">
    134                  <xs:restriction base="xs:string">
    135                          <xs:minLength value="1"/>
    136                          <xs:maxLength value="24"/>
    137                  </xs:restriction>
    138          </xs:simpleType>
    139          <xs:simpleType name="DateType">
    140                  <xs:restriction base="xs:date"/>
    141          </xs:simpleType>
    142          <xs:simpleType name="CommentsType">
    143                  <xs:restriction base="xs:string">
    144                          <xs:minLength value="1"/>
    145                          <xs:maxLength value="2048"/>
    146                  </xs:restriction>
    147          </xs:simpleType>
    148          <xs:simpleType name="DescriptionType">
    149                  <xs:restriction base="xs:string">
    150                          <xs:minLength value="1"/>
    151                          <xs:maxLength value="256"/>
    152                  </xs:restriction>
    153          </xs:simpleType>
    154  </xs:schema>
    155  ');
    156  begin
    157    if (dbms_xdb.existsResource(:schemaPath)) then
    158      dbms_xdb.deleteResource(:schemaPath);
    159    end if;
    160    res := dbms_xdb.createResource(:schemaPath,xmlSchema);
    161  end;
    162  /
    PL/SQL procedure successfully completed.
    SQL> begin
      2    dbms_xmlschema.registerSchema
      3    (
      4      :schemaURL,
      5      xdbURIType(:schemaPath).getClob(),
      6      TRUE,TRUE,FALSE,FALSE
      7    );
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    SQL> create or replace view PURCHASEORDER_XML
      2  of xmltype
      3  xmlSCHEMA "http://xfiles:8080/home/SCOTT/poSource/xsd/purchaseOrder.xsd" Element "PurchaseOrder"
      4  with object id
      5  (
      6    substr(extractValue(object_value,'/PurchaseOrder/Reference'),1,32)
      7  )
      8  as
      9    select xmlElement
    10           (
    11             "PurchaseOrder",
    12             xmlAttributes
    13             (
    14               'http://xfiles:8080/home/SCOTT/poSource/xsd/purchaseOrder.xsd' as "xsi:noNamespaceSchemaLocation",
    15               'http://www.w3.org/2001/XMLSchema-instance' as "xmlns:xsi"
    16             ),
    17             xmlElement("Reference",p.REFERENCE),
    18             xmlElement
    19             (
    20               "Actions",
    21               ( select xmlAgg
    22                        (
    23                          xmlElement
    24                          (
    25                            "Action",
    26                            xmlElement("User",ACTIONEDBY),
    27                            case
    28                              when DATEACTIONED is not null
    29                              then xmlElement("Date",DATEACTIONED)
    30                            end
    31                          )
    32                        )
    33                   from PURCHASEORDER_ACTION a
    34                  where a.REFERENCE = p.REFERENCE
    35               )
    36             ),
    37             xmlElement
    38             (
    39               "Reject",
    40                  xmlForest
    41                  (
    42                    REJECTEDBY as "User",
    43                 DATEREJECTED as "Date",
    44                    COMMENTS as "Comments"
    45                  )
    46             ),
    47             xmlElement("Requestor",REQUESTER),
    48             xmlElement("User",USERID),
    49             xmlElement("CostCenter",COSTCENTER),
    50             xmlElement
    51             (
    52               "ShippingInstructions",
    53               xmlElement("name",SHIPTONAME),
    54               xmlElement("address",ADDRESS),
    55               xmlElement("telephone",PHONE)
    56             ),
    57             xmlElement("SpecialInstructions",SPECIALINSTRUCTIONS),
    58             xmlElement
    59             (
    60               "LineItems",
    61               ( select xmlAgg
    62                        (
    63                          xmlElement
    64                          (
    65                            "LineItem",
    66                            xmlAttributes(LINENO as "ItemNumber"),
    67                            xmlElement("Description",DESCRIPTION),
    68                            xmlElement
    69                            (
    70                              "Part",
    71                              xmlAttributes
    72                              (
    73                                UPC       as "Id",
    74                                QUANTITY  as "Quantity",
    75                                UNITPRICE as "UnitPrice"
    76                              )
    77                            )
    78                          )
    79                        )
    80                    from PURCHASEORDER_LINEITEM l
    81                   where l.REFERENCE = p.REFERENCE
    82               )
    83             )
    84           )
    85      from PURCHASEORDER_TABLE p, PURCHASEORDER_REJECTION r, PURCHASEORDER_SHIPPING s
    86     where r.REFERENCE = p.REFERENCE
    87       and s.REFERENCE = p.REFERENCE
    88  /
    View created.
    SQL> set long 10000 pages 0 lines 140
    SQL> --
    SQL> select x.object_value.extract('/*')
      2    from PURCHASEORDER_XML x
      3  /
    <PurchaseOrder xsi:noNamespaceSchemaLocation="http://xfiles:8080/home/SCOTT/poSource/xsd/purchaseOrder.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <Reference>SMCCAIN-20030109123335470PDT</Reference>
      <Actions>
        <Action>
          <User>SVOLLMAN</User>
        </Action>
      </Actions>
      <Reject/>
      <Requestor>Samuel B. McCain</Requestor>
      <User>SMCCAIN</User>
      <CostCenter>A10</CostCenter>
      <ShippingInstructions>
        <name>Samuel B. McCain</name>
        <address>800 Bridge Parkway,Redwood Shores,CA,94065,USA</address>
        <telephone>650 506 7800</telephone>
      </ShippingInstructions>
      <SpecialInstructions>Courier</SpecialInstructions>
      <LineItems>
        <LineItem ItemNumber="1">
          <Description>Life of Brian - Monty Python&apos;s</Description>
          <Part Id="715515010320" Quantity="2" UnitPrice="39.95"/>
        </LineItem>
        <LineItem ItemNumber="2">
          <Description>The Night Porter</Description>
          <Part Id="37429145227" Quantity="2" UnitPrice="29.95"/>
        </LineItem>
        <LineItem ItemNumber="3">
          <Description>Oliver Twist</Description>
          <Part Id="37429128121" Quantity="1" UnitPrice="39.95"/>
        </LineItem>
        <LineItem ItemNumber="4">
          <Description>Notorious</Description>
          <Part Id="715515012720" Quantity="4" UnitPrice="39.95"/>
        </LineItem>
        <LineItem ItemNumber="5">
          <Description>In the Mood for Love</Description>
          <Part Id="715515012928" Quantity="3" UnitPrice="39.95"/>
        </LineItem>
        <LineItem ItemNumber="6">
          <Description>Alphaville</Description>
          <Part Id="37429130926" Quantity="2" UnitPrice="29.95"/>
        </LineItem>
        <LineItem ItemNumber="7">
          <Description>General Idi Amin Dada</Description>
          <Part Id="37429166529" Quantity="4" UnitPrice="29.95"/>
        </LineItem>
        <LineItem ItemNumber="8">
          <Description>In the Mood for Love</Description>
          <Part Id="715515012928" Quantity="3" UnitPrice="39.95"/>
        </LineItem>
        <LineItem ItemNumber="9">
          <Description>Flesh for Frankenstein</Description>
          <Part Id="715515009423" Quantity="3" UnitPrice="39.95"/>
        </LineItem>
        <LineItem ItemNumber="10">
          <Description>The Killer</Description>
          <Part Id="715515008976" Quantity="1" UnitPrice="39.95"/>
        </LineItem>
        <LineItem ItemNumber="11">
          <Description>Ballad of a Soldier</Description>
          <Part Id="37429167922" Quantity="2" UnitPrice="29.95"/>
        </LineItem>
        <LineItem ItemNumber="12">
          <Description>Ordet</Description>
          <Part Id="37429158623" Quantity="2" UnitPrice="0"/>
        </LineItem>
      </LineItems>
    </PurchaseOrder>
    SQL> begin
      2    for x in (select object_value from PURCHASEORDER_XML) loop
      3      x.object_value.schemaValidate();
      4    end loop;
      5  end;
      6  /
    PL/SQL procedure successfully completed.
    SQL>

  • Has anybody tried creating and validating a XML doc with XML Schema?

    Hi,
    Has anybody tried creating and validating a XML doc with XML Schema?

    With XMLBeans, an XML document may be created from and validated with an XML schema.

  • Problem inserting and querying XML data with a recursive XML schema

    Hello,
    I'm facing a problem with querying XML data that is valid against a recursive XML Schema. I have got a table category that stores data as binary XML using Oracle 11g Rel 2 on Windows XP. The XML Schema is the following:
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="bold_type" mixed="true">
              <xs:choice minOccurs="0" maxOccurs="unbounded">
                   <xs:element name="bold" type="bold_type"/>
                   <xs:element name="keyword" type="keyword_type"/>
                   <xs:element name="emph" type="emph_type"/>
              </xs:choice>
         </xs:complexType>
         <xs:complexType name="keyword_type" mixed="true">
              <xs:choice minOccurs="0" maxOccurs="unbounded">
                   <xs:element name="bold" type="bold_type"/>
                   <xs:element name="keyword" type="keyword_type"/>
                   <xs:element name="emph" type="emph_type"/>
                   <xs:element name="plain_text" type="xs:string"/>
              </xs:choice>
         </xs:complexType>
         <xs:complexType name="emph_type" mixed="true">
              <xs:choice minOccurs="0" maxOccurs="unbounded">
                   <xs:element name="bold" type="bold_type"/>
                   <xs:element name="keyword" type="keyword_type"/>
                   <xs:element name="emph" type="emph_type"/>
              </xs:choice>
         </xs:complexType>
         <xs:complexType name="text_type" mixed="true">
              <xs:choice minOccurs="0" maxOccurs="unbounded">
                   <xs:element name="bold" type="bold_type"/>
                   <xs:element name="keyword" type="keyword_type"/>
                   <xs:element name="emph" type="emph_type"/>
              </xs:choice>
         </xs:complexType>
         <xs:complexType name="parlist_type">
              <xs:sequence>
                   <xs:element name="listitem" minOccurs="0" maxOccurs="unbounded" type="listitem_type"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="listitem_type">
              <xs:choice minOccurs="0" maxOccurs="unbounded">
                   <xs:element name="parlist" type="parlist_type"/>
                   <xs:element name="text" type="text_type"/>
              </xs:choice>
         </xs:complexType>
         <xs:element name="category">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="name"/>
                        <xs:element name="description">
                                  <xs:complexType>
                                            <xs:choice>
                                                           <xs:element name="text" type="text_type"/>
                                                           <xs:element name="parlist" type="parlist_type"/>
                                            </xs:choice>
                                  </xs:complexType>
                        </xs:element>
                                                                </xs:sequence>
                                                                <xs:attribute name="id"/>
                                            </xs:complexType>
                        </xs:element>
    </xs:schema>I registered this schema and created the category table. Then I inserted a new row using the code below:
    insert into category_a values
    (XMlElement("category",
          xmlattributes('categoryAAA' as "id"),
          xmlforest ('ma categ' as "name"),
          (xmlelement("description", (xmlelement("text", 'find doors blest now whiles favours carriage tailor spacious senses defect threat ope willow please exeunt truest assembly <keyword> staring travels <bold> balthasar parts attach </bold> enshelter two <emph> inconsiderate ways preventions </emph> preventions clasps better affections comes perish </keyword> lucretia permit street full meddle yond general nature whipp <emph> lowness </emph> grievous pedro')))    
    The row is successfully inserted as witnessed by the results of row counting. However, I cannot extract data from the table. First, I tried using SqlPlus* which hangs up and quits after a while. I then tried to use SQL Developer, but haven't got any result. Here follow some examples of queries and their results in SQL Developer:
    Query 1
    select * from category
    Result : the whole row is returned
    Query 2
    select xmlquery('$p/category/description' passing object_value as "p" returning content) from category
    Result: "SYS.XMLTYPE"
    now I tried to fully respect the nested structure of description element in order to extract the text portion of <bold> using this query
    Query 3
    select  xmlquery('$p/category/description/text/keyword/bold/text()' passing object_value as "p" returning content) from  category_a
    Result: null
    and also tried to extract the text portion of element <text> using this query
    Query 4
    select  xmlquery('$p/category/description/text/text()' passing object_value as "p" returning content) from  category_a
    Result: "SYS.XMLTYPE".
    On the other hand, I noticed, from the result of query 1, that the opening tags of elements keyword and bold are encoded as the less than operator "&lt;". This explains why query 3 returns NULL. However, query 4 should display the text content of <text>, which is not the case.
    My questions are about
    1. How to properly insert the XML data while preserving the tags (especially the opening tag).
    2. How to display the data (the text portion of the main Element or of the nested elements).
    The problem about question 1 is that it is quite unfeasible to write a unique insert statement because the structure of <description> is recursive. In other words, if the structure of <description> was not recursive, it would be possible to embed the elements using the xmlelement function during the insertion.
    In fact, I need to insert the content of <description> from a source table (called category_a) into a target table (+category_b+) automatically .
    I filled category_a using the Saxloader utility from an flat XML file that I have generated from a benchmark. The content of <description> is different from one row to another but it is always valid with regards to the XML Schema. The data is properly inserted as witnessed by the "select * from category_a" instruction (500 row inserted). Besides, the opening tags of the nested elements under <description> are preserved (no "&lt;"). Then I wrote a PL/SQL procedure in which a cursor extracts the category id and category name into varchar2 variables and description into an XMLtype variable from category_a. When I try to insert the values into a category_b, I get the follwing error:
    LSX-00213: only 0 occurrences of particle "text", minimum is 1which tells that the <text> element is absent (actually it is present in the source table).
    So, my third question is why are not the tags recognized during the insertion?
    Can anyone help please?

    Hello,
    indded, I was using an old version of Sqlplus* (8.0.60.0.0) because I had a previous installation (oracle 10g XE). Instead, I used the Sqlplus* shipped with the 11g2database (version 11.2.0.1.0). All the queries that I wrote work fine and display the data correctly.
    I also used the XMLSERIALIZE function and can now display the description content in SQL Developer.
    Thank you very much.
    To answer your question Marco, I registered the XML Schema using the following code
    declare
      doc varchar2(4000) := '<?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="bold_type" mixed="true">
              <xs:choice minOccurs="0" maxOccurs="unbounded">
                   <xs:element name="bold" type="bold_type"/>
                   <xs:element name="keyword" type="keyword_type"/>
                   <xs:element name="emph" type="emph_type"/>
              </xs:choice>
         </xs:complexType>
         <xs:complexType name="keyword_type" mixed="true">
              <xs:choice minOccurs="0" maxOccurs="unbounded">
                   <xs:element name="bold" type="bold_type"/>
                   <xs:element name="keyword" type="keyword_type"/>
                   <xs:element name="emph" type="emph_type"/>
                   <xs:element name="plain_text" type="xs:string"/>
              </xs:choice>
         </xs:complexType>
         <xs:complexType name="emph_type" mixed="true">
              <xs:choice minOccurs="0" maxOccurs="unbounded">
                   <xs:element name="bold" type="bold_type"/>
                   <xs:element name="keyword" type="keyword_type"/>
                   <xs:element name="emph" type="emph_type"/>
              </xs:choice>
         </xs:complexType>
         <xs:complexType name="text_type" mixed="true">
              <xs:choice minOccurs="0" maxOccurs="unbounded">
                   <xs:element name="bold" type="bold_type"/>
                   <xs:element name="keyword" type="keyword_type"/>
                   <xs:element name="emph" type="emph_type"/>
              </xs:choice>
         </xs:complexType>
         <xs:complexType name="parlist_type">
              <xs:sequence>
                   <xs:element name="listitem" minOccurs="0" maxOccurs="unbounded" type="listitem_type"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="listitem_type">
              <xs:choice minOccurs="0" maxOccurs="unbounded">
                   <xs:element name="parlist" type="parlist_type"/>
                   <xs:element name="text" type="text_type"/>
              </xs:choice>
         </xs:complexType>
         <xs:element name="category">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="name"/>
                        <xs:element name="description">
                                  <xs:complexType>
                                            <xs:choice>
                                                           <xs:element name="text" type="text_type"/>
                                                           <xs:element name="parlist" type="parlist_type"/>
                                            </xs:choice>
                                  </xs:complexType>
                        </xs:element>
                                                                </xs:sequence>
                                                                <xs:attribute name="id"/>
                                            </xs:complexType>
                        </xs:element>
    </xs:schema>';
    begin
      dbms_xmlschema.registerSchema('/xmldb/category_auction.xsd', doc,     LOCAL      => FALSE, 
            GENTYPES   => FALSE,  GENBEAN    => FALSE,   GENTABLES  => FALSE,
             FORCE      => FALSE,
             OPTIONS    => DBMS_XMLSCHEMA.REGISTER_BINARYXML,
             OWNER      => USER);
    end;then, I created the Category table as follows:
    CREATE TABLE category_a of XMLType XMLTYPE store AS BINARY XML
        XMLSCHEMA "xmldb/category_auction.xsd" ELEMENT "category";Now, there still remains a problem of how to insert the "description" content which I serialized as a CLOB data into another table as XML. To this purpose, I wrote a view over the Category_a table as follows:
    CREATE OR REPLACE FORCE VIEW "AUCTION_XWH"."CATEGORY_V" ("CATEGORY_ID", "CNAME", "DESCRIPTION") AS
      select category_v."CATEGORY_ID",category_v."CNAME",
      XMLSerialize(content ( xmlquery('$p/category/description/*' passing object_value as "p" returning content)) as clob) as "DESCRIPTION"
      from  auction.category_a p, 
    xmltable ('$a/category' passing p.Object_Value as "a"
    columns  category_id varchar2(15) path '@id',
              cname varchar2(20) path 'name') category_v;Then, I wrote a procedure to insert data into the Category_xwh table (the source and target tables are slightly different: the common elements are just copied wereas new elements are created in the target table). The code of the procedure is the following:
    create or replace PROCEDURE I_CATEGORY AS
    v_cname VARCHAR2(30);
    v_description clob ;
    v_category_id VARCHAR2(15);
    cursor mycursor is select category_id, cname, description from category_v;
    BEGIN
    open mycursor;
      loop
      /*retrieving the columns*/
      fetch mycursor into v_category_id, v_cname, v_description ;
      exit when mycursor%notfound;
      insert into category_xwh values
      (XMlElement("category",
          xmlattributes(v_category_id as "category_id"),
          xmlelement("Hierarchies", xmlelement("ObjHierarchy", xmlelement ("H_Cat"),
                                                               xmlelement ("Rollsup",
                                                                                  (xmlelement("all_categories",
                                                                                   xmlattributes('allcategories' as "all_category_id")))
        xmlforest (
                  v_cname as "cat_name",
                  v_description as "description")    
    end loop;
      commit;
      close mycursor;
    END I_CATEGORY;When I execute the procedure, I get the following error:
    LSX-00201: contents of "description" should be elements onlyso, I just wonder if this is because v_description is considered as plain text and not as XML text, even if its content is XML. Do I need to use a special function to cast the CLOB as XML?
    Thanks for your help.
    Doulkifli

  • XML validation with JDOM / JAXP

    Hello,
    I am trying to validate xml file against schema file. I decided to use JDOM and JAXP.
    First question: is it a good choice?
    I did a first attempt but not sure I have understood all what I am doing :(
    First I have create a parser usinf org.jdom.*
    SAXBuilder parser = new SAXBuilderThen I built my document:
    Document doc = parser.build(myFile)These 2 steps are ok. But it does not do validation.
    I saw in the JDOM documentation that I can set a validation flag to true. I did it. First problem, I got the following error from JDOMException: Document is invalid: no grammar found.
    Is there a way to specify to the parser where to find the xsd file?
    As I did not find answer to this question by myself, I tried implementing the Schema class from JAXP:
    SAXBuilder parser = new SAXBuilder;
    Document doc = parser.build(myFile);
    Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(schemaFile);
    ValidatorHandler vh = schema.newValidatorHandler();
    SAXOutputter so = new SAXOutputter(vh);
    so.output(doc);It does the validation against the schema file specified but I am not really sure about what I am doing here. The last 2 commands are not clear to me :(
    Then in my schema file, I have elements that have default value. I expected the following behavior: if the element is not in the xml file then the default will be used by the parser (and added in the tree). But it seems, it's not the case.
    Any help/explanation will be really appreciated.

    I am trying to validate xml file against schema file. I decided to use JDOM and JAXP.
    First question: is it a good choice?
    If only schema validation is required use the validation API in JDK 5.0.
    http://www-128.ibm.com/developerworks/xml/library/x-javaxmlvalidapi.html
    http://java.sun.com/developer/technicalArticles/xml/validationxpath/
    For validation with JDOM, the following validation application explains the procedure:import org.jdom.input.SAXBuilder;
    import org.xml.sax.SAXException;import org.jdom.*;
    import java.io.*;
    public class JDOMValidator{
    public void validateSchema(String SchemaUrl, String XmlDocumentUrl){
               try{
    SAXBuilder saxBuilder = new SAXBuilder("org.apache.xerces.parsers.SAXParser",true);<br/>saxBuilder.setValidation(true);
    saxBuilder.setFeature("http://apache.org/xml/features/validation/schema",true);
    saxBuilder.setFeature("http://apache.org/xml/features/validation/schema-full-checking",true);
    saxBuilder.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",SchemaUrl);
    Validator handler=new Validator();
    saxBuilder.setErrorHandler(handler);
    saxBuilder.build(XmlDocumentUrl);
    if(handler.validationError==true)
    System.out.println("XML Document has Error:"+handler.validationError+""+
    handler.saxParseException.getMessage());      
    else           
          System.out.println("XML Document is valid");
              }catch(JDOMException jde){
                }catch(IOException ioe){
    private class Validator extends DefaultHandler{     
         public boolean  validationError = false; 
         public SAXParseException saxParseException=null;    
      public void error(SAXParseException exception) throws SAXException{        
         validationError =true;
         saxParseException=exception; 
      public void fatalError(SAXParseException exception) throws SAXException  {
    validationError = true;     
    saxParseException=exception;
      public void warning(SAXParseException exception) throws SAXException       {
    public static void main(String[] argv)   {
       String SchemaUrl=argv[0];StringXmlDocumentUrl=argv[1];
       JDOMValidator validator=new JDOMValidator();
       validator.validateSchema(SchemaUrl,XmlDocumentUrl);
    }

  • XML Schema Collection (SQL Server 2012): Complex Schema Collection with Attribute - Should xs or xsd be used in the coding?

    Hi all,
    I just got a copy of the book "Pro SQL Server 2008 XML" written by Michael Coles (published by Apress) and try to learn the XML Schema Collection in my SQL Server 2012 Management Studio (SSMS2012). I studied Chapter 4 XML Collection of the book
    and executed the following code of Listing 4-8 Complex Schema with Attribute:
    -- Pro SQL Server 2008 XML by Michael Coles (Apress)
    -- Listing04-08.sql Complex XML Schema with Attribute
    -- shcColes04-08.sql saved in C:\\Documents\XML_SQL_Server2008_code_Coles_Apress
    -- 6 April 2015 8:00 PM
    CREATE XML SCHEMA COLLECTION dbo.ComplexTestSchemaCollection_attribute
    AS
    N'<?xml version="1.0"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="item">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="name" />
    <xs:element name="color" />
    <xs:group ref="id-price" />
    <xs:group ref="size-group" />
    </xs:sequence>
    <xs:attribute name="id" />
    <xs:attribute name="number" />
    </xs:complexType>
    </xs:element>
    <xs:group name="id-price">
    <xs:choice>
    <xs:element name="list-price" />
    <xs:element name="standard-cost" />
    </xs:choice>
    </xs:group>
    <xs:group name="size-group">
    <xs:sequence>
    <xs:element name="size" />
    <xs:element name="unit-of-measure" />
    </xs:sequence>
    </xs:group>
    </xs:schema>';
    GO
    DECLARE @x XML (dbo.ComplexTestSchemaCollection_attribute);
    SET @x = N'<?xml version="1.0"?>
    <item id="749" number="BK-R93R-62">
    <name>Road-150 Red, 62</name>
    <color>Red</color>
    <list-price>3578.27</list-price>
    <size>62</size>
    <unit-of-measure>CM</unit-of-measure>
    </item>';
    SELECT @x;
    GO
    DROP XML SCHEMA COLLECTION dbo.ComplexTestSchemaCollection_attribute;
    It worked nicely. But, I just found out the coding that was downloaded from the website of Apress and I just executed was different from the coding of Listing 4-8 listed in the book: all the <xs: ....> and </xs: ..> in my SSMS2012 are
    listed as <xsd:...> and </xsd:...> respectively in the book!!??  The same thing happens in the Listing 4-3 Simple XML Schema, Listing 4-5 XML Schema and Valid XML Document with Comple Type Definition, Listion 4-6 XML Schema and XML
    Document Document with Complex Type Using <sequence> and <choice>, and Listing 4-7 Complex XML Schema and XML Document with Model Group Definition (I executed last week) too.  I wonder: should xs or xsd be used in the XML
    Schema Collection of SSMS2012?  Please kindly help,  clarify this matter and explain the diffirence of using xs and xsd for me.
    Thanks in advance,
    Scott Chang   

    Hi Scott,
    Using xs or xsd depends on how you declare the namespace prefix.
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="item">
    I've posted a very good link in your last question, just in case you might have missed it, please see the below link.
    Understanding XML Namespaces
    In an XML document we use a namespace prefix to qualify the local names of both elements and attributes . A prefix is really just an abbreviation for the namespace identifier (URI), which is typically quite long. The prefix is first mapped to a namespace
    identifier through a namespace declaration. The syntax for a namespace declaration is:
    xmlns:<prefix>='<namespace identifier>'
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • Error in xml file validation to its relevant xml schema

    Hi All,
    I have 3 xml schema files files from which I generated a XML file using PLSQL.I am getting this error when I am trying to validate xml file to the schema:
    *'WMWROOT' NOT DECLARED*.Can anyone help me with this,I am including the main schema file and also the XML generated.
    XML Schem file:
    Itemdownload.xsd:
    <?xml version="1.0" encoding="utf-8" ?>
    <xs:schema id="ItemDownload" targetNamespace="http://www.manh.com/ILSNET/Interface" elementFormDefault="qualified"
         xmlns="http://www.manh.com/ILSNET/Interface" xmlns:xs="http://www.w3.org/2001/XMLSchema" version ="2007">
         <xs:include schemaLocation="Item.xsd" />
    <xs:element name="WMWROOT" nillable="true" type="WMWROOT" />
    <xs:complexType name="WMWROOT">
    <xs:sequence>
    <xs:element minOccurs="0" maxOccurs="1" name="WMWDATA" type="WMWDATA" />
    </xs:sequence>
    </xs:complexType>
    <xs:element name="WMWDATA" nillable="true" type="WMWDATA"/>
    <xs:complexType name="WMWDATA">
    <xs:sequence>
    <xs:element minOccurs="0" maxOccurs="1" name="Items" type="ItemList" />
    </xs:sequence>
    </xs:complexType>
    <xs:element name="Items" nillable="false" type="ItemList" />
    <xs:complexType name="ItemList">
    <xs:sequence>
    <xs:element minOccurs="1" maxOccurs="unbounded" name="Item" nillable="true" type="Item" />
    </xs:sequence>
    </xs:complexType>
    </xs:schema>
    The generated xml file is:
    <?xml version="1.0" ?>
    <WMWROOT>
    <WMWDATA>
    <Items>
    <Item><Action>Save</Action><UserDef8>10074</UserDef8><Active>Y</Active><AvailableOnWeb>N</AvailableOnWeb><Company>OU: ResMed Corp</Company><Cost>285.93</Cost><Desc>HP DESKJET PRINTER (EMBLA)</Desc><HarmCode><UserDef8>10074</UserDef8></HarmCode><Item>R145-794</Item><InventoryTracking>Y</InventoryTracking><LongDesc>HP DESKJET PRINTER (EMBLA)</LongDesc><LotControlled>Y</LotControlled><SerialNumTrackOutbound>7</SerialNumTrackOutbound><StorageTemplate><Template>Each</Template></StorageTemplate><XRefs><XRef><XRefItem></XRefItem></XRef></XRefs></Item>
    <Item><Action>Save</Action><UserDef8>80862</UserDef8><Active>Y</Active><AvailableOnWeb>N</AvailableOnWeb><Company>OU: ResMed Corp</Company><Cost>54.27</Cost><Desc>Mirage Micro Mask MED&amp;LG-Internet Pkg</Desc><HarmCode><UserDef8>80862</UserDef8></HarmCode><Item>16359</Item><InventoryTracking>Y</InventoryTracking><LongDesc>Mirage Micro Mask MED&amp;LG-Internet Pkg</LongDesc><LotControlled>Y</LotControlled><SerialNumTrackOutbound>N</SerialNumTrackOutbound><StorageTemplate><Template>Each</Template></StorageTemplate><XRefs><XRef><XRefItem>619498163597</XRefItem></XRef></XRefs></Item>
    </Items>
    </WMWDATA>
    </WMWROOT>
    I can provide you with the other 2 dependent schemas if needed.Please reply me!!

    Hey,
    As you said I tried keeping the namespace in xml file and it worked for a strange reason I am getting the same error again,I am not able to figure it why!!
    The error is:
    SAMPLEITEMDLFILE.xml:2,139: no declaration found for element 'WMWROOT'
    The XML document SAMPLEITEMDLFILE.xml is NOT valid (1 errors)
    This is the part of PL/SQL code thru which I am generating the xml:
    UTL_FILE.put_line (l_out_file, '<?xml version="1.0" ?>');
    UTL_FILE.put_line (l_out_file, '<WMWROOT');
    UTL_FILE.put_line (l_out_file, 'xmlns="http://www.manh.com/ILSNET/Interface"> ');
    UTL_FILE.put_line (l_out_file, '<WMWDATA>');
    UTL_FILE.put_line (l_out_file, '<Items>');
    I am validating it in stylus studio tool.
    Can you please help me thru this?

  • Validation of XML-Schema

    I have a question, if in the XDK there is a
    possibility to check a .xsd file, if it belongs to the XML Schema Definition http://www.w3.org/2000/10/XMLSchema
    Thanks for your help
    Greetings, Merry Christmas and Happy new Year
    Andreas

    Simply use the self-same XML Schema Processor to validate your *.xsd schema against the schema for XML Schema itself. That is, the XML Schema spec "ships" with a normative XML Schema which describes the valid elements that a schema author can use to write a schema. If you have a particular XML schema definition in hand, it is in particular an instance of a document that should be valid by the XML schema for XML Schema, if you've done it correctly.

  • ORA-19007 when coping a table with an xml type in it to a new schema in the

    ORA-19007 when coping a table with an xml type in it to a new schema in the same database.
    Hi all,
    When I copy a table with an xml type in it to a new schema in the same database I get an ora-19009.
    The setup is as follows I have a schema a with table TABLE_WITH_XMLTYPE where data is:
    CREATE
    TABLE TABLE_WITH_XMLTYPE
    FOLDER_ID NUMBER (10, 0) NOT NULL,
    SEARCH_PROPERTIES XMLTYPE ,
    CONSTRAINT TABLE_WITH_XMLTYPE PK PRIMARY KEY (FOLDERID) USING INDEX
    XMLTYPE COLUMN SEARCH_PROPERTIES XMLSCHEMA
    "http://xxxxxxx.net/FolderProperties.xsd" element "FolderProperties"
    VARRAY SEARCH_PROPERTIES."XMLDATA"."PROPERTIES"."PROPERTY" STORE AS TABLE
    PROPERTY_TABLE
    (PRIMARY KEY (NESTED_TABLE_ID, ARRAY_INDEX)) ORGANIZATION INDEX OVERFLOW
    Both schemas have the following xml schema registered as a local xml schema
    BEGIN
    DBMS_XMLSCHEMA.registerSchema(
    SCHEMAURL => 'http://xxxxxxx.net/FolderProperties.xsd',
    SCHEMADOC =>
    '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xdb="http://xmlns.oracle.com/xdb"
    xdb:storeVarrayAsTable="true">
    <xs:element name="FolderProperties"
    type="FolderPropertiesType"
    xdb:defaultTable="FOLDER_SEARCH_PROPERTIES" />
    <xs:complexType name="FolderPropertiesType" xdb:SQLType="FOLDERPROPERTIES_T">
    <xs:sequence>
    <xs:element name="FolderID" type="FolderIDType" minOccurs="1" xdb:SQLName="FOLDER_ID"/>
    <xs:element name="Properties" type="PropertiesType" xdb:SQLName="PROPERTIES"/>
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="PropertiesType" xdb:SQLType="PROPERTIES_T">
    <xs:sequence>
    <xs:element name="Property" type="PropertyType" maxOccurs="unbounded"
    xdb:SQLName="PROPERTY" xdb:SQLCollType="PROPERTY_V"/>
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="PropertyType" xdb:SQLType="PROPERTY_T">
    <xs:sequence>
    <xs:element name="DateValue" type="DateType" xdb:SQLName="DATE_VALUE"/>
    <xs:element name="NumValue" type="NumType" xdb:SQLName="NUM_VALUE"/>
    <xs:element name="StringValue" type="StringType" xdb:SQLName="STRING_VALUE"/>
    </xs:sequence>
    <xs:attribute name="Name" xdb:SQLName="NAME" xdb:SQLType="VARCHAR2">
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:minLength value="1"/>
    <xs:maxLength value="255"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:attribute>
    </xs:complexType>
    <xs:simpleType name="FolderIDType">
    <xs:restriction base="xs:integer"/>
    </xs:simpleType>
    <xs:simpleType name="DateType">
    <xs:restriction base="xs:dateTime"/>
    </xs:simpleType>
    <xs:simpleType name="NumType">
    <xs:restriction base="xs:decimal"/>
    </xs:simpleType>
    <xs:simpleType name="StringType">
    <xs:restriction base="xs:string" />
    </xs:simpleType>
    </xs:schema>',
    LOCAL => TRUE,
    GENTYPES => TRUE,
    GENTABLES => FALSE);
    END;
    when I try to do the following insert:
    insert into schemaB.TABLE_WITH_XMLTYPE ( FOLDER_ID, SEARCH_PROPERTIES)
    select FOLDER_ID, SEARCH_PROPERTIES from schemaB.TABLE_WITH_XMLTYPE;
    I’ll get an ora-19007.
    Can some one point me in the right direction how to solve this error.
    Thanks Roelof.

    Who did you create the second table, in other words, how did you COPY the table as you said...
    If you created the second table via a CTAS (create table as select) then you will have created a table that is not the same as the original one. AFAIK I have once created an enhancement request for this after discovering that JDeveloper, for example, creates a "copy" via a CTAS which creates the wrong structure. Double check via package DBMS_METADATA.
    SQL> set long 1000000
    SQL> select DBMS_METADATA('TABLE','TABLE_WITH_XMLTYPE','SchemaA') from dual;
    SQL> select DBMS_METADATA('TABLE','TABLE_WITH_XMLTYPE','SchemaB') from dual;If you have got two different tables, than Mark's solution should help.
    M.
    Edited by: Marco Gralike on Feb 15, 2009 11:16 AM

Maybe you are looking for