【发布时间】:2021-11-12 18:08:59
【问题描述】:
这是一个小架构和一个示例 XML 文件,如果选择 XSD 1.1 版而不是 XSD 1.0,它将在 Xerces-J online validation service 成功验证。
选择 1.0 时,架构本身被拒绝,因为从 t1 派生 t2 无效。 (意图是t1 允许可选的thing 和一些stuff,而t2 是保留stuff 但禁止thing 的限制。)
选择 1.0 的 Xerces-J 的确切投诉是:
[Error] foo.xsd:19:28:rcase-Recurse.1: Group's occurrence range, (0,unbounded), is not a valid restriction of base group's occurrence range, (1,1).
[Error] foo.xsd:19:28:derivation-ok-restriction.5.4.2: Error for type 't2'. The particle of the type is not a valid restriction of the particle of the base.
我认为发生的情况是 t2 中包含的 <sequence> 被认为是“无意义的”(2.2.2.2.1 here),因为它现在只有一个孩子,但对应的t1 中的 <sequence> 不是“毫无意义的”,因为它有两个孩子,并且派生检查器试图将 t2 的 <group> 的 minOccurs 和 maxOccurs 与 t1 的 t1 匹配年代<sequence>。不知何故,XSD 1.1 的检查器比这更聪明。
所以我的问题(好的,两个问题):
-
1.0 中的这种行为是 XSD 1.0 的固有已知限制,1.1 中的派生规则已更新以修复,还是 1.0 的
Xerces-J实现 的限制?有人有接受此架构的 1.0 实现吗? -
鉴于使用 1.0 的工具的持续部署,是否有人知道编写此架构的另一种方法可以在 1.0 中使用? (我可以通过丢失
<group>并内联<stuff>元素来使这个示例工作,但如果现实生活中的组有多个孩子,这不是一个计划。
编辑:如果元素领导一个替换组,即使内联解决方法也无效。这被具体化为here 为<choice> 组,它的minOccurs 和maxOccurs 与基本类型的<sequence> 不匹配。
foo.xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
targetNamespace="foo:bar"
xmlns="foo:bar">
<xs:group name="stuffGroup">
<xs:sequence>
<xs:element name="stuff"/>
</xs:sequence>
</xs:group>
<xs:complexType name="t1">
<xs:sequence>
<xs:element name="thing" minOccurs="0"/>
<xs:group ref="stuffGroup" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="t2">
<xs:complexContent>
<xs:restriction base="t1">
<xs:sequence>
<xs:group ref="stuffGroup" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:element name="a" type="t2"/>
</xs:schema>
foo.xml:
<a xmlns='foo:bar'/>
【问题讨论】: