对 XML 模式进行版本控制的最佳实践是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2014237/
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
What are the best practices for versioning XML schemas?
提问by Regent
I often have to design XML schemas for different XML-bases import routines. It is clear that XML schemas will evolve over time or they could contain bugs to be fixed, so it is important to capture the schema's version and to have some mechanism to bind against a specific version.
我经常需要为不同的基于 XML 的导入例程设计 XML 模式。很明显,XML 模式会随着时间的推移而发展,或者它们可能包含需要修复的错误,因此捕获模式的版本并拥有某种机制来绑定特定版本是很重要的。
Currently I have two scenarios:
目前我有两种情况:
The bug is found within the schema and all schema instances must comply with the fixed version.
The schema upgraded and should be considered as preferable but an old one should be also supported.
该错误是在架构中发现的,并且所有架构实例都必须符合固定版本。
架构已升级,应被视为更可取,但也应支持旧架构。
Finally I came up with storing version information within the namespace of schema:
最后我想出了在模式的命名空间中存储版本信息:
targetNamespace="http://schemas.company.com/Geodesy/2010/River.xsd"
When fixing a bug I fix it in the same namespace but if I'm about to upgrade a schema then I need to create a new namespace but with upgrade month added:
修复错误时,我将其修复在同一个命名空间中,但是如果我要升级架构,那么我需要创建一个新的命名空间,但添加了升级月份:
targetNamespace="http://schemas.company.com/Geodesy/2010/01/River.xsd"
And if I have more than one upgrade in a month then just append a day too:
如果我在一个月内进行了多次升级,那么也只需添加一天:
targetNamespace="http://schemas.company.com/Geodesy/2010/01/17/River.xsd"
Do you know any better approach?
你知道有什么更好的方法吗?
回答by xcut
This is such a difficult subject that it's not even funny, and one that I have spent years providing consultancy support for.
这是一个如此困难的主题,它甚至都不好笑,而且我花了数年时间为其提供咨询支持。
There are many best practicesout there, but a most of them do not work in all situations. For example, many advocate the use of "xsd:any" to allow extensions, and that is just a recipe for disaster if developers are in charge of maintaining the schema, turning it into a dump.
有许多最佳实践,但其中大多数并不适用于所有情况。例如,许多人提倡使用“xsd:any”来允许扩展,如果开发人员负责维护模式,将其变成转储,那只会导致灾难。
Here are some tips for you if you're getting started:
如果您刚开始使用,这里有一些提示:
- Do notput a minor version number, micro version number, date, or anything else of the sort, into your namespace. Every time you change the namespace, you will break all processing applications.
- Doput a "version" attribute in the XML instance document. That will enable a processing application or a version adapter service to figure out what it is processing.
- Dospecify a policy of what constitutes a backwards compatible change, for example: adding optional elements will not break senders, and will not break receivers either if they use a policy of ignoring elements they do not know (JAXB and XMLBeans can be configured this way)
- 千万不能把一个小版本号,微版本号,日期,或任何东西的那种东西,到您的命名空间。每次更改命名空间时,都会中断所有处理应用程序。
- 请在 XML 实例文档中放置一个“版本”属性。这将使处理应用程序或版本适配器服务能够确定它正在处理的内容。
- 请指定构成向后兼容更改的策略,例如:添加可选元素不会破坏发送者,也不会破坏接收者,如果他们使用忽略不知道的元素的策略(JAXB 和 XMLBeans 可以这样配置) )
Dood luck!
祝你好运!
回答by Christian
http://www.xml.com/pub/a/2004/07/21/design.htmlprovides good guidelines and XML Schema 1.1 enables 'versioning' through conditional inclusion (http://www.w3.org/TR/xmlschema11-1/#cip).
http://www.xml.com/pub/a/2004/07/21/design.html提供了很好的指导方针,XML Schema 1.1 通过条件包含实现了“版本控制”(http://www.w3.org/TR/ xmlschema11-1/#cip)。

