Where to add a version to an XSD schema?

青春壹個敷衍的年華 提交于 2019-11-30 08:17:21

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>

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)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!