dbms10 (1) 38
dbms10 (1) 38
AIM
To Create an XML database and validate it using XML schema.
DECLARE
l_schema CLOB;
BEGIN
<xs:element name="item">
<xs:complexType>
<xs:sequence>
<xs:element ref="title"/>
<xs:element ref="note" minOccurs="0"/>
<xs:element ref="quantity"/>
<xs:element ref="price"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="shiporder">
<xs:complexType>
<xs:sequence>
<xs:element ref="orderperson"/>
<xs:element ref="shipto"/>
<xs:element ref="item" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute ref="orderid" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>';
We can check the schema details using the USER_XML_SCHEMAS view. 721222104031
------------------------------------------------------------------------------
--
With the schema registered, we can now validate XML documents against it.
The DELETESCHEMA procedure can be used to un-register the schema.
The DELETE_OPTION parameter allows you to drop any dependent objects.
BEGIN
DBMS_XMLSCHEMA.deleteschema(
schemaurl => 'my_schema.xsd',
delete_option => DBMS_XMLSCHEMA.delete_cascade_force);
END;
/
DECLARE
l_xml CLOB;
l_xmltype XMLTYPE;
BEGIN
END;
/
To see an example of a validation failure, rename the "name" tag to "name1". This is
not part of the XML schema, so it will fail the validation.
DECLARE
l_xml CLOB;
l_xmltype XMLTYPE;
BEGIN
END;
/
CREATE TABLE t1 (
id NUMBER,
xml XMLTYPE
);
COMMIT;
Now we can use the XMLISVALID function in SQL to test against the registered XML
721222104031
Schema. It returns a "1" if the XML is valid, and "0" if it isn't.
---------- ----------
RESULT:
To Create the XML database and XML Schema are Validate Successfully.
721222104031