【问题标题】:Converting XSD 1.1 to 1.0 - Validation Error将 XSD 1.1 转换为 1.0 - 验证错误
【发布时间】:2015-08-30 12:28:13
【问题描述】:

当我尝试验证此 XSD 时:

<xs:group name="ValidityDateGroup">
    <xs:annotation>
        <xs:documentation>Reusable element group to be used where Valid From/Until needs to be captured in xs:date format</xs:documentation>
    </xs:annotation>
    <xs:all>
        <xs:element minOccurs="0" name="ValidFrom" type="xs:date"/>
        <xs:element minOccurs="0" name="ValidUntil" type="xs:date"/>
    </xs:all>
</xs:group>

<xs:complexType name="NameType">
    <xs:choice maxOccurs="unbounded" minOccurs="0">
        <!-- SNIP - many more choices here -->
        <xs:group ref="ValidityDateGroup"/>  <!-- THIS IS WHERE THE ERROR IS -->
     </xs:choice>
</xs:complexType>

我收到以下错误:

一个“所有”模型组必须出现在一个粒子中,“{'min occur'}' = '{'max occur'}' = 1,并且该粒子必须是构成“{”内容的一对type'}' 的复杂类型定义。

我能够让它作为 1.0 XSD 工作的唯一方法是将“全部”更改为“序列”:

<xs:group name="ValidityDateGroup">
    <xs:annotation>
        <xs:documentation>Reusable element group to be used where Valid From/Until needs to be captured in xs:date format</xs:documentation>
    </xs:annotation>
    <xs:sequence>
        <xs:element minOccurs="0" name="ValidFrom" type="xs:date"/>
        <xs:element minOccurs="0" name="ValidUntil" type="xs:date"/>
    </xs:sequence>
</xs:group>

但这会强制执行特定的顺序。

有没有人知道如何让这个 XSD 与 XSD 1.0 一起工作?

【问题讨论】:

    标签: xml xsd xsd-1.0


    【解决方案1】:

    你不能让它与 XSD 1.0 一起工作。不允许将“全部”作为选择的一部分。在 1.1 中也是如此。

    但是你真正想要达到的目标是什么?您只能选择一个分支,这显然是多余的,只是它指定了 max=unbounded。您的“全部”组表示 From 和 Until 都是可选的,可以按任意顺序出现,而您的 max=unbounded 表示该组可以出现任意次数。对我来说,如果这意味着什么,那就意味着你的内容可以包含任意数量的 From 元素和任意数量的 Until 元素,并且它们可以按照你喜欢的任何顺序出现。也就是说,它的意思是

    <choice maxOccurs="unbounded">
      <element name="From"/>
      <element name="Until"/>
    </choice>
    

    【讨论】:

    • 对不起 - 我不够清楚。此 XSD 来自需要在 .NET 中解析的 WSDL(因此必须是 XSD 1.0)。选择有很多分支 - 我只是将它们剪掉,因为它们不相关 - 现在已修复。
    【解决方案2】:

    我设法根据迈克尔的回答完成了这项工作,但将选择包装在 ValidityDateGroup 中的一个序列中:

    <xs:group name="ValidityDateGroup">
        <xs:sequence>
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element minOccurs="0" name="ValidFrom" type="xs:date"/>
                <xs:element minOccurs="0" name="ValidUntil" type="xs:date"/>
            </xs:choice>
        </xs:sequence>
    </xs:group>
    

    因此,引用 Michael 的话,我的内容“可以包含任意数量的 From 元素和任意数量的 Until 元素,并且它们可以以任意顺序出现”。这也保留了 ValidityDateGroup 可以在其他地方重用。

    【讨论】:

      猜你喜欢
      • 2016-08-13
      • 2018-05-24
      • 1970-01-01
      • 2015-03-11
      • 1970-01-01
      • 1970-01-01
      • 2017-09-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多