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

标签 xml xsd xml-validation

<分区>

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

ParticipantObjectIdentificationContents 对象中是否需要元素 SOPClass

<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>

最佳答案

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

关于xml - 如果未指定其多重性,是否需要该元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8748237/

相关文章:

c# - 如何在 ASP.NET CORE 中签署 XML SAML 断言

java - 架构位置偶数个 URI 的编码

java - 针对 XSD 的 xml 验证 : Invalid content was found starting with element xxx

xml - "Non whitespace characters are not allowed in schema elements "

java - 如何防止 Xerces 访问 Internet 以获取系统 ID URI?

php - 跟踪每个人每月的通话次数——MySQL 还是 XML?

c - 在 Windows 中找不到 libxml/xmlversion.h 文件

java - SAX 字符缓冲区大小

绑定(bind)到前缀的XML模式导入-vs-命名空间

c# - XmlReader 始终根据另一个 Xsd 文件验证 Xsd 文件是否有效