【问题标题】:XSD validation of an element defined as an empty choice定义为空选项的元素的 XSD 验证
【发布时间】:2016-12-13 00:42:29
【问题描述】:

我遇到了带有空选项的 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 评估为 Schema 有效。

不知道哪个评价结果是正确的。

【问题讨论】:

    标签: xml xsd xsd-validation


    【解决方案1】:

    一个空的xs:choiceallowed 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 拥有任何属性和内容模型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-05
      • 1970-01-01
      • 1970-01-01
      • 2011-03-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多