在序列而不是元素级别使用 min/maxOccurs 时的任何差异 [英] Any difference when you use min/maxOccurs at sequence rather than element level

查看:24
本文介绍了在序列而不是元素级别使用 min/maxOccurs 时的任何差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的意思是有没有这样的情况:

What I mean is are there any situations where this:

<xs:element name="MyType1">
    <xs:complexType>
        <xs:sequence>
            <xs:element maxOccurs="unbounded" name="MyType2">...</xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

对此有不同的含义:

<xs:element name="MyType1">
    <xs:complexType>
        <xs:sequence maxOccurs="unbounded">
            <xs:element name="MyType2">...</xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

提前致谢

推荐答案

一般来说,元素组(序列或选择)上的出现约束(minOccursmaxOccurs)意味着整个组可以重复,而元素的出现约束意味着该元素可以在组中的下一个元素出现之前重复.

Generally speaking occurrence constraints (minOccurs or maxOccurs) on element groups (sequences or choices) mean that the whole group can be repeated whereas occurrence constraints on elements mean that the element can be repeated before the next element in the group appears.

如果您的序列只包含一个元素,则没有区别.

If your sequence contains only one element, there is no difference.

<xs:sequence>
    <xs:element maxOccurs="unbounded" name="MyType2">...</xs:element>
</xs:sequence>

等于

<xs:sequence maxOccurs="unbounded">
    <xs:element name="MyType2">...</xs:element>
</xs:sequence>

并且它们都允许重复元素 .只要序列包含多个元素定义,就会有差异.

and they both allow repeating the element <MyType2>. There will be a difference as soon as the sequence contains more than one element definition.

<xs:sequence>
    <xs:element maxOccurs="unbounded" name="MyType">...</xs:element>
    <xs:element maxOccurs="unbounded" name="foobar">...</xs:element>
</xs:sequence>

等于

<xs:sequence maxOccurs="unbounded">
    <xs:element name="MyType">...</xs:element>
    <xs:element name="foobar">...</xs:element>
</xs:sequence>

第一个允许像

<MyType/>
<MyType/>
<foobar/>
<foobar/>

但第二个不允许这样的结构.相反,它允许像

but the second one doesn't allow such a structure. Instead it allows structures like

<MyType/>
<foobar/>
<MyType/>
<foobar/>

另一方面,第一个定义不允许.

which on the other hand are not allowed by the first definition.

这篇关于在序列而不是元素级别使用 min/maxOccurs 时的任何差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆