XSD 验证定义为空选择的元素
XSD validation of an element defined as an empty choice
我遇到了空选择的 XSD 元素定义:
<xs:element name="Data">
<xs:complexType>
<xs:choice>
</xs:choice>
</xs:complexType>
</xs:element>
当我获取元素实例时:
<Data/>
在 XML 文档中,某些解析器(SoapUI、Oracle SOA 12c)将其评估为错误:
元素 Data@http://www.namespace.com/ensc).
中的预期元素
而其他人(Eclipse 工具)将 XML 评估为架构有效。
不知道哪个评价结果是正确的
空 xs:choice
是 allowed in XSD:
<choice
id = ID
maxOccurs = (nonNegativeInteger | unbounded) : 1
minOccurs = nonNegativeInteger : 1
{any attributes with non-schema namespace . . .}>
Content: (annotation?, (element | group | choice | sequence | any)*)
</choice>
请注意,Content:
可能包含一个 可选的 annotation
,然后是 零 或更多 (element | group | choice | sequence | any)
。因此,您的 XSD 没问题,仅由 Data
组成的 XML 文档对它有效。
您的 XSD 可以简化为
<xs:element name="Data">
<xs:complexType/>
</xs:element>
但是请注意,它不能进一步简化为
<xs:element name="Data"/>
因为这实际上允许 Data
具有 任何 属性和内容模型。
我遇到了空选择的 XSD 元素定义:
<xs:element name="Data">
<xs:complexType>
<xs:choice>
</xs:choice>
</xs:complexType>
</xs:element>
当我获取元素实例时:
<Data/>
在 XML 文档中,某些解析器(SoapUI、Oracle SOA 12c)将其评估为错误: 元素 Data@http://www.namespace.com/ensc).
中的预期元素而其他人(Eclipse 工具)将 XML 评估为架构有效。
不知道哪个评价结果是正确的
空 xs:choice
是 allowed in XSD:
<choice
id = ID
maxOccurs = (nonNegativeInteger | unbounded) : 1
minOccurs = nonNegativeInteger : 1
{any attributes with non-schema namespace . . .}>
Content: (annotation?, (element | group | choice | sequence | any)*)
</choice>
请注意,Content:
可能包含一个 可选的 annotation
,然后是 零 或更多 (element | group | choice | sequence | any)
。因此,您的 XSD 没问题,仅由 Data
组成的 XML 文档对它有效。
您的 XSD 可以简化为
<xs:element name="Data">
<xs:complexType/>
</xs:element>
但是请注意,它不能进一步简化为
<xs:element name="Data"/>
因为这实际上允许 Data
具有 任何 属性和内容模型。