問題描述
我有一個模式 (a),它導(dǎo)入了另一個模式 (z).然后我有另一個模式 (b) 導(dǎo)入相同的模式 (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."
但氧氣也不例外.
我想以不引發(fā)此異常的方式配置 .net.只是為了表現(xiàn)得像氧氣.
I'd like to configure .net the way it does NOT throw this exception. Just to behave like Oxygen.
怎么做?
推薦答案
出現(xiàn)問題是因為 XSD 建議允許但不要求一致的處理器忽略從已經(jīng)遇到的命名空間導(dǎo)入 XSD..NET 正在重新導(dǎo)入,這是允許的.氧氣忽略了重新進口,這是允許的.
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:
注意:以上措辭謹慎,同一架構(gòu)文檔的多次<import>
不會構(gòu)成違反條款2 of 架構(gòu)屬性正確 (§3.15.6),但應(yīng)用程序允許(實際上是鼓勵)避免 <import>
使用相同的模式多次記錄以防止建立的必要性身份組件逐個組件.鑒于 schemaLocation
[attribute] 只是一個提示,它是開放給應(yīng)用程序忽略所有但是給定命名空間的第一個 <import>
,無論schemaLocation
的實際價值,但是這樣的策略有缺失的風(fēng)險提供新的 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 theschemaLocation
[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· ofschemaLocation
, but such a strategy risks missing useful information when newschemaLocations
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.)
這篇關(guān)于多次導(dǎo)入同一個 XSD 會出錯嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!