The following scenario demonstrates the process of evolving an XML schema registered in the XML schema repository (XSR).
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="prodType">
<xsd:sequence>
<xsd:element name="name" type="xsd:string" />
<xsd:element name="sku" type="xsd:string" />
<xsd:element name="price" type="xsd:integer" />
</xsd:sequence>
<xsd:attribute name="color" type="xsd:string" />
<xsd:attribute name="weight" type="xsd:integer" />
</xsd:complexType>
<xsd:element name="products">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="product" type="prodType" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
REGISTER XMLSCHEMA 'http://product'
FROM 'file://c:/schemas/prod.xsd'
AS STORE.PROD
COMPLETE XMLSCHEMA STORE.PROD
After
the XML schema was registered, the XML-formatted product lists were
validated against it and inserted into the store database.<xsd:complexType name="prodType">
<xsd:sequence>
<xsd:element name="name" type="xsd:string" />
<xsd:element name="sku" type="xsd:string" />
<xsd:element name="price" type="xsd:integer" />
<xsd:element name="description" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="color" type="xsd:string" />
<xsd:attribute name="weight" type="xsd:integer" />
</xsd:complexType>
In the XML schema segment to insert, the "minOccurs" attribute
is set to "0". This is important, for otherwise "description" would
become a mandatory element as part of the content model, and all of
the existing XML documents that were validated against the original
schema and inserted into the database tables would no longer be in
a valid state. To evolve an XML schema, the original and the new version
of that schema must be compatible. For details, see Compatibility
requirements for evolving an XML schema.REGISTER XMLSCHEMA 'http://newproduct'
FROM 'file://c:/schemas/newprod.xsd'
AS STORE.NEWPROD
COMPLETE XMLSCHEMA STORE.NEWPROD
CALL SYSPROC.XSR_UPDATE(
'STORE',
'PROD',
'STORE',
'NEWPROD',
1)
The original XML schema is evolved. All of the external dependencies managed in the XSR for XML instance documents that were previously validated against the XML schema STORE.PROD are updated based on the contents of the XML schema STORE.NEWPROD. Because the dropnewschema parameter is set by passing a non-zero value, the new schema STORE.NEWPROD is dropped after the original schema is updated.
Any existing XML documents that have already been validated against the original XML schema are not validated again as a result of the update procedure. Instead, a check is performed during the update to confirm that the original and new XML schemas are compatible, thereby ensuring that any documents previously validated against the original XML schema will also be valid against the new one. In the previous example, setting the "minOccurs" attribute to "0" in the new "description" element is required for the two XML schemas to be compatible. Any XML documents that are inserted after the schema evolution will be validated against the newly updated version of STORE.PROD, and these documents can now contain "description" elements for each store product.