xml 在哪里向 XSD 架构添加版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2138705/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 12:56:29  来源:igfitidea点击:

Where to add a version to an XSD schema?

xmlxsdversion

提问by elifiner

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.

我处理的应用程序具有符合 XSD 架构的 XML 输出。随着功能添加到应用程序中,XSD 发生了变化,我想注意 XSD 文件中架构的版本。

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?

你怎么做呢?

回答by peter_raven

You can use the namespace of your xsd document

您可以使用 xsd 文档的命名空间

<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 changingthe 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).

以 w3.org 定义的 xsd 为例,他们就是这样做的。请注意,根据定义,更改此处的版本号通常对您的 xsd 的任何使用者来说都是一个重大更改(无论实际更改有多小,或者您更改了版本号的哪一部分)。

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>

回答by Roland Bouman

According to the schemaelement itself has a versionattribute:

根据schema元素本身有一个version属性:

<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"

参见http://www.w3.org/TR/xmlschema-1/#key-schema,“3.15.2XML 模式表示”

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)

但是,如果您发布了架构,那么我认为处理它的最佳方法是使用目标命名空间。这将强制使用正确的版本(但会破坏兼容性)