Schema versioning - change schemaLocation, but keep same namespace ?

Where you have an XSD schema, and want to create a new version of the schema that adds a couple of elements, is changing the schemaLocation hint a sensible way to indicate that an XML document is using a newer version of the schema Or is changing the targetNamespace the way to do this

For example: notice the different value for schemaLocation:

<mt395 xmlns="urn:incident:mt395" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:incident:mt395 mt395-1.xsd">

<mt395 xmlns="urn:incident:mt395" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:incident:mt395 mt395-2.xsd">

Irrespective of SQL Server 2005, is this a sensible approach for XML

I believe SQL Server 2005 requires a new targetNamespace if using typed XML, so I couldn't use this approach in the database. Would this be a sensible enhancment to SQL Server to allow it to store different XML documents against multiple versions of a schema, using the schemaLocation to identify the specific version Or is this generally considered a bad idea in the XML world

Thanks,

Andy Mackie



Answer this question

Schema versioning - change schemaLocation, but keep same namespace ?

  • Shailesh Patel

    SchemaLocations are only hints according to the XML Schema validation semantics and should not be used for versioning.

    Using a new namespace may be an option, but is quite heavy weight. Only recommended if everything changes or for new parts.

    In SQL Server you can just create a new schema collection for the new data if you don't have to store the data of both versions in the same collection.

    Best regards

    Michael



  • Tee40

    OK thanks.

    Any thoughts on using the version attribute within an XSD to indicate a schema is a new version Downside is it's totally optional, and can be ignored by validating parsers. e.g.

    <xsd:schema ... version="1.2" >

    Or alternatively, use custom version attributes on the root element This enables validation to be enforced against a specific schema version. e.g.

    Schema:

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"; targetNamespace="http://www.example.com/doc";>

    <xs:element name="doc">
    <xs:complexType>
    <xs:extension base="xs:string">
    <xs:attribute name="version" use="required" fixed="2.3.1" />
    </xs:extension>
    </xs:complexType>
    </xs:element>
    </xs:schema>

    Instance document

    <doc xmlns="http://www.example.com/doc"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://www.example.com/doc http://www.example.com/doc/2.3.1/doc.xsd";
    version="2.3.1">Hello World!</doc>

    It seems that we need both a targetNamespace, and some form of version number, to uniquely identify a schema, if we don't want XPath statements to be totally re-written everytime a targetNamespace changes.


  • Schema versioning - change schemaLocation, but keep same namespace ?