4

我的架构的这一部分给我带来了麻烦:

        <xs:element name="newrecipients">
            <xs:complexType>
                <xs:choice>
                    <xs:element name="csv" type="xs:string" />
                    <!-- List of recipients -->
                </xs:choice>
            </xs:complexType>
        </xs:element>

收件人列表是以下内容的列表:

<recipient>
    <field1>...</field1>
    ...
    <fieldN>...</field>
</recipient>

其中标签接收者可以包含模式未知的随机标签序列。所以我用了类似的东西

  <xs:element name="recipient">
    <xs:complexType>
      <xs:sequence>
        <xs:any minOccurs="1"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

问题是我不知道如何定义收件人列表。我知道<xs:list>,但我不明白在这种情况下如何使用它,因为通常我会看到类似

<xs:element name="intvalues" type="valuelist">

<xs:simpleType name="valuelist">
  <xs:list itemType="xs:integer"/>
</xs:simpleType>

</xs:schema>

您必须在其中定义一个包含列表的元素。我想要直接csv或直接的list.

我错过了什么?谢谢。

编辑:输出示例

这:

<newrecipients>
    <csv>myrecipients.csv</csv>
</newrecipients>

或这个:

<newrecipients>
    <recipient>
        <field1>...</field1>
        ...
        <fieldN>...</field>
    </recipient>
    ...
    <recipient>
        <field1>...</field1>
        ...
        <fieldN>...</field>
    </recipient>
</newrecipients>
4

1 回答 1

5

我不确定它在xsd:choice元素内是否有效:

<xs:element name="newrecipients">
    <xs:complexType>
        <xs:choice>
            <xs:element name="csv" type="xs:string" />
            <!-- List of recipients -->
            <xs:element name="recipient" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:sequence>
                        <xs:any minOccurs="1"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:choice>
    </xs:complexType>
</xs:element>

当然,您可以使用此解决方案将元素声明包装在xsd:sequence标签内,但我不知道当且仅当缺少 csv 元素时您是否希望列表存在。

于 2012-07-11T07:42:07.503 回答