多次导入同一个 XSD 会出错吗?

Is it an error to import the same XSD multiple times?(多次导入同一个 XSD 会出错吗?)
本文介绍了多次导入同一个 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).

这样,符合模式 (a) 的 XML 文档 (d) 也可以包含符合模式 (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 of 架构属性正确 (§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.

幸运的是,Oxygen 基于 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 会出错吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Custom Error Queue Name when using EasyNetQ for RabbitMQ?(使用 EasyNetQ for RabbitMQ 时自定义错误队列名称?)
Rabbitmq Ack or Nack, leaving messages on the queue(Rabbitmq Ack 或 Nack,将消息留在队列中)
Wait for a single RabbitMQ message with a timeout(等待一条带有超时的 RabbitMQ 消息)
Setup RabbitMQ consumer in ASP.NET Core application(在 ASP.NET Core 应用程序中设置 RabbitMQ 消费者)
How do I set a number of retry attempts in RabbitMQ?(如何在 RabbitMQ 中设置重试次数?)
WebClient set headers(WebClient 设置标头)