具有可选子元素的默认XML序列(或全部)必须至少有一个子元素吗?

具有可选子元素的默认XML序列(或全部)必须至少有一个子元素吗?,xml,xsd,xsd-validation,xml-validation,Xml,Xsd,Xsd Validation,Xml Validation,如果有人能确认以下模式的解释是否正确,我将不胜感激: <xs:element name="Element1"> <xs:complexType> <xs:sequence> <xs:element name="Child1" minOccurs="0" /> <xs:element name="Child2" minOccurs="0" /> &l

如果有人能确认以下模式的解释是否正确,我将不胜感激:

<xs:element name="Element1">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="Child1" minOccurs="0" />
            <xs:element name="Child2" minOccurs="0" /> 
        </xs:sequence>
    </xs:complexType>
</xs:element>
他不会答应的。要使其有效,需要序列
minOccurs=0
(?)

更新

当子元素是可选的时,这个问题与序列(和所有)的出现意义有关。例如,文件

<Element1>
    <Child2/>
    <Child1/>
</Element1>

将符合上述模式。这个序列会发生两次;在第一个过程中,
Child1
缺席。在第二组中,
Child2
缺失。但关键是,序列
minOccurs
(默认值为1)得到了满足,因为它发生了两次

对于我上面给出的第一个示例(只是
Element1
;没有子元素),序列根本不发生,并且(IMO)不满足
minOccurs=1

具有可选子元素的默认XML序列(或全部)必须至少有一个子元素吗

尽管
Child1
Child2
都是可选的,
Element1
必须至少有一个 至少有一个子项符合上述架构

minOccurs
的默认值是
1
,因此您可以正确地假设
xsd:sequence
被约束为只显示一次。但是,
xsd:sequence minOccurs=“1”
只要满足其子项的出现约束一次就可以满足。当所有子引用约束都是
minOccurs=“0”
时,允许一个空序列。 因此,
是有效的,即使没有任何
Child1
Child2
子元素

另请参见


其他例子: XSD与
xs:sequence minOccurs=“0”

<xs:element name="r">
    <xs:complexType>
        <xs:sequence minOccurs="0" maxOccurs="1">
            <xs:element name="a"/>
            <xs:element name="b"/> 
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:element name="r">
    <xs:complexType>
        <xs:sequence minOccurs="2" maxOccurs="2">
            <xs:element name="a"/>
            <xs:element name="b"/> 
        </xs:sequence>
    </xs:complexType>
</xs:element>
有效XML:

XSD与
xs:sequence minOccurs=“2”

<xs:element name="r">
    <xs:complexType>
        <xs:sequence minOccurs="0" maxOccurs="1">
            <xs:element name="a"/>
            <xs:element name="b"/> 
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:element name="r">
    <xs:complexType>
        <xs:sequence minOccurs="2" maxOccurs="2">
            <xs:element name="a"/>
            <xs:element name="b"/> 
        </xs:sequence>
    </xs:complexType>
</xs:element>


有效XML:

感谢您的耐心等待。如果序列的出现是由其条件得到满足,并且序列的出现计数表示其条件得到满足的次数,那么我想问一下minOccurs=0的序列的行为将如何解释。由于这是一个与上述不同的查询,我是否应该单独提问?@CAnder:Answer更新了
xs:sequence
minOccurs
的更多示例。