如果未指定多重性,是否需要元素?

时间:2012-01-05 19:04:46

标签: xml xsd xml-validation

我正在编写一个库,它根据XSD中定义的XML消息格式生成xml消息。但是,我对以下架构有几个问题:

SOPClass对象中是否需要元素ParticipantObjectIdentificationContents

<xs:complexType name="ParticipantObjectIdentificationContents">
    <xs:sequence>
        <!-- there are other elements here -->
        <xs:group ref="DICOMObjectDescriptionContents"/>
        <!-- there are other elements here -->
    </xs:sequence>
</xs:complexType>
<xs:group name="DICOMObjectDescriptionContents">
    <xs:sequence>
        <!-- there are other elements here -->
        <xs:element ref="SOPClass"/>
        <!-- there are other elements here -->
    </xs:sequence>
</xs:group>
<xs:element name="SOPClass">
    <xs:complexType>
        <xs:sequence>
            <xs:element minOccurs="0" maxOccurs="unbounded" ref="Instance"/>
        </xs:sequence>
        <xs:attribute name="UID" type="xs:token"/>
        <xs:attribute name="NumberOfInstances" use="required" type="xs:integer"/>
    </xs:complexType>
</xs:element>
<xs:element name="Instance">
    <xs:complexType>
        <xs:attribute name="UID" use="required" type="xs:token"/>
    </xs:complexType>
</xs:element>

1 个答案:

答案 0 :(得分:5)

是。 minOccursmaxOccurs的默认值为1,因此SOPClass必须只出现一次。见XML Schema minOccurs / maxOccurs default values