We would like to register the following XML schema in Oracle:
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Id">
<xsd:simpleType>
<xsd:restriction base="xsd:integer"></xsd:restriction></xsd:simpleType>
</xsd:element>
<xsd:element name="FirstName">
<xsd:simpleType>
<xsd:restriction base="xsd:string"><xsd:maxLength value="35" /></xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="LastName">
<xsd:simpleType>
<xsd:restriction base="xsd:string"><xsd:maxLength value="35" /></xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="Person">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Id" />
<xsd:element ref="FirstName" />
<xsd:element ref="LastName" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!-- MAIN ELEMENT -->
<xsd:element name="People">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Person" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
To register it in the Oracle DB execute the following script:
begin
dbms_xmlschema.registerSchema(
'SchemaName.xsd',
'insert schema here...',
genTypes => true,
genTables => false,
local => true
);
end;
/
The script registers the schema and also creates types based on the elements in the xsd. If we register xsd schemas this way, the genereted types are not good to use in programs (plsql procedure, function,...) because the names of types are generated internally (if we delete the schema and register the same one again the names are different!!!).We can see all the registered schemas in oracle:
select * from user_xml_schemas
To delete any registered schema, execute this:
begin
dbms_xmlschema.deleteSchema('People.xsd',dbms_xmlschema.DELETE_CASCADE);
end;
/
The proper way the xsd schema should look, will be discribed in the next post :)
Ni komentarjev:
Objavite komentar