Where to add a version to an XSD schema?
Solution 1
You can use the namespace of your xsd document
<xs:schema targetNamespace="http://yourcompany/yourapp/1.0" ... >
...
</xs:schema>
As an example look at the xsd's defined by w3.org, this is how they do it. Do note that changing the version number here would usually by definition be a breaking change for any consumers of your xsd (no matter how small the actual change was, or which part of the version number you changed).
For less impacting versioning, there seems to be an agreement about putting a version attribute at your root element:
<xs:schema version="1.0.0" ...>
...
</xs:schema>
Solution 2
According to the schema
element itself has a version
attribute:
<schema
attributeFormDefault = (qualified | unqualified) : unqualified
blockDefault = (#all | List of (extension | restriction | substitution)) : ''
elementFormDefault = (qualified | unqualified) : unqualified
finalDefault = (#all | List of (extension | restriction | list | union)) : ''
id = ID
targetNamespace = anyURI
version = token
xml:lang = language
{any attributes with non-schema namespace . . .}>
Content: ((include | import | redefine | annotation)*, (((simpleType | complexType | group | attributeGroup) | element | attribute | notation), annotation*)*)
</schema>
See http://www.w3.org/TR/xmlschema-1/#key-schema, "3.15.2 XML Representations of Schemas"
However, if you published the schema, then I think the best way to deal with it would be to use the target namespace. This would enforce the right version being used (but break compatibility)
Related videos on Youtube
elifiner
Updated on July 09, 2022Comments
-
elifiner almost 2 years
The application I work on has XML output that conforms to an XSD schema. As features are added to the application, the XSD changes and I would like to note the version of the schema in the XSD file.
Perhaps I'm missing something, but I haven't found a built-in way to mark the version of the schema.
How do you do it?
-
Karussell about 14 yearsWhy not specify the version into the xsd file name? e.g. myschema1.0.xsd
-
elifiner about 14 yearsThis is a great idea actually.
-
DanSkeel almost 11 years
-
-
Roland Bouman about 14 yearsI think this is an appropriate solution when changing major version. However, its not so good if you want to do a correction or new development iteration, because al XML documents would have to be migrated to a new namespace. The version attribute of the schema element like I point out in my seems more appropriate for those cases IMO.
-
DanSkeel almost 11 yearsBad answer. See recommendations. Also you can try this
-
DanSkeel almost 11 yearsFrom xml-google-styleguide:
Namespaces MUST NOT be changed unless the semantics of particular elements or attributes has changed in drastically incompatible ways. [Rationale: Changing the namespace requires changing all client code.]
-
CMPE over 6 yearsIs there a way to get the version from the root? ie <xs:schema... version="1.0"/>