对 XML 模式进行版本控制的最佳实践是什么? [英] What are the best practices for versioning XML schemas?

查看:32
本文介绍了对 XML 模式进行版本控制的最佳实践是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常需要为不同的基于 XML 的导入例程设计 XML 模式.很明显,XML 模式会随着时间的推移而发展,或者它们可能包含需要修复的错误,因此捕获模式的版本并拥有某种机制来绑定特定版本非常重要.

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.

目前我有两种情况:

  1. 在架构中发现了错误,所有架构实例都必须符合修复版本.

  1. 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.

最后我想出了在 schema 的命名空间中存储版本信息:

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"

你知道更好的方法吗?

推荐答案

这是一个非常困难的主题,甚至都不好笑,而且我花了多年时间为其提供咨询支持.

This is such a difficult subject that it's not even funny, and one that I have spent years providing consultancy support for.

有许多最佳实践,但其中大部分都不起作用情况.例如,许多人提倡使用xsd:any"来允许扩展,如果开发人员负责维护架构,将其变成转储,那只会导致灾难.

There are many best practices out 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.

如果您刚开始,这里有一些提示:

Here are some tips for you if you're getting started:

  • 不要不要将次要版本号、微版本号、日期或任何其他类型的内容放入您的命名空间中.每次更改命名空间时,都会中断所有处理应用程序.
  • 在 XML 实例文档中放置一个版本"属性.这将使处理应用程序或版本适配器服务能够确定它正在处理的内容.
  • 是否指定构成向后兼容更改的策略,例如:添加可选元素不会破坏发送者,也不会破坏接收者,如果他们使用忽略元素的策​​略,他们不会知道(JAXB 和 XMLBeans 可以这样配置)
  • Do not put 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.
  • Do put 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.
  • Do specify 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 模式进行版本控制的最佳实践是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆