多次导入同一XSD是否出错? [英] Is it an error to import the same XSD multiple times?

查看:103
本文介绍了多次导入同一XSD是否出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个架构(a),可以导入另一个架构(z)。
然后,我还有另一个模式(b),它导入了相同的模式(z)。

I have a schema (a) that imports another schema (z). Then I have yet another schema (b) that imports that same schema (z).

发生这种情况是为了使XML文档(d)符合模式( a)也可以包含符合架构(z)的可选元素。

It happens so that XML document (d) conforming to schema (a) can also contain an optional element that conforms to schema (z).

因此,当(d)在.NET中经过验证时,我遇到了异常 simpleType'z:x'已经被声明。

In consequence, when (d) is validated in .NET, I'm having exception "The simpleType 'z:x' has already been declared."

但是氧气没有例外。

我想以不引发此异常的方式配置.net。只是表现得像氧气。

I'd like to configure .net the way it does NOT throw this exception. Just to behave like Oxygen.

如何?

推荐答案

问题出现这种情况是由于XSD建议允许(但不要求)一致的处理器忽略从已经遇到的命名空间中导入XSD。 .NET正在重新导入,这是允许的。氧气正像允许的那样忽略了重新进口。

The problem arises due to the XSD Recommendation allowing, but not requiring, conformant processors to ignore the import of an XSD from an already encountered namespace. .NET is re-importing, as it is allowed to do. Oxygen is ignoring re-imports, as it is allowed to do.

两者的运行都符合XSD建议。请参见 4.2.3跨命名空间的架构组件的引用

Both are operating in conformance to the XSD Recommendation. See the last note in 4.2.3 References to schema components across namespaces:


注意:上面的措辞很谨慎,因此多个< import> ; 对同一模式文档的访问不会违反条款
2 rel = nofollow noreferrer>架构属性正确(第3.15.6节),但是确实鼓励使用
应用程序,以避免< import> 使用相同的架构
文件不止一次,以阻止建立每个组件
个身份组件的必要性。鉴于 schemaLocation
[attribute]仅是一个提示,它可以让应用程序忽略所有
,但忽略第一个 < import> 给定命名空间,而不考虑 schemaLocation
·实际值·,但是这样的策略可能会丢失
提供新的 schemaLocations 时的有用信息。

Note: The above is carefully worded so that multiple <import>ing of the same schema document will not constitute a violation of clause 2 of Schema Properties Correct (§3.15.6), but applications are allowed, indeed encouraged, to avoid <import>ing the same schema document more than once to forestall the necessity of establishing identity component by component. Given that the schemaLocation [attribute] is only a hint, it is open to applications to ignore all but the first <import> for a given namespace, regardless of the ·actual value· of schemaLocation, but such a strategy risks missing useful information when new schemaLocations are offered.

幸运的是,氧气基于Xerces,它允许用户通过以下方式控制此行为:

Fortunately, Oxygen is based on Xerces, which allows the user to control this behavior via


http://apache.org/xml/features/honour-all-schemaLocations

不幸的是,.NET XML / XSD处理器不是基于Xerces的,并且我不知道任何.NET版本中的任何并行配置选项。 (如果没有另外显示,我会很乐意更新此答案。)

Unfortunately, the .NET XML/XSD processor is not based on Xerces, and I am unaware of any parallel configuration option in any .NET version. (I will happily update this answer if shown otherwise.)

这篇关于多次导入同一XSD是否出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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