微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

是否应该始终默认缺少枚举的 XML 属性?

如何解决是否应该始终默认缺少枚举的 XML 属性?

如果 XML 元素中缺少定义为枚举列表的属性,如果未指定认值,是否应将列表中的第一个值用作认值?

我在架构中有以下内容

<xsd:simpleType name="YesNoType">
    <xsd:restriction base="xsd:string">
        <xsd:enumeration value="yes"/>
        <xsd:enumeration value="no"/>
    </xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="Telephonestructure">
    <xsd:sequence>
        <xsd:element name="TelNationalNumber" type="core:TelephoneNumberType"/>
        <xsd:element name="TelExtensionNumber" type="core:TelephoneExtensionType" minOccurs="0"/>
        <xsd:element name="TelCountryCode" type="core:TelCountryCodeType" minOccurs="0"/>
    </xsd:sequence>
    <xsd:attribute name="TelUse" type="core:WorkHomeType"/>
    <xsd:attribute name="TelMobile" type="core:YesNoType"/>
    <xsd:attribute name="TelPreferred" type="core:YesNoType"/>
</xsd:complexType>

我已经从上述架构生成了 C# 类型。我预计缺少的属性会导致空值,但我发现缺少的属性认为列表中的第一个值,根据 XML 规范,这是否正确?

解决方法

根据您的架构,只有 TelExtensionNumberTelCountry code 是可选的。其他都不是可选的,因此将采用默认值(0 表示 int,null 表示类)。

How to make an element in XML schema optional?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。