【发布时间】:2021-06-10 17:05:36
【问题描述】:
如果定义为枚举列表的属性从 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 规范这是正确的吗?
【问题讨论】:
-
给定默认值。请参阅:w3schools.com/xml/schema_simple.asp
-
据我所知,从 XML 到 C# 的映射不受任何 W3C(或其他)标准的约束,这完全是产品设计师的事情,
-
@MichaelKay XML 规范肯定说明了 XML 应该如何解释?
-
它说默认值应该报告给应用程序,但它没有说明应用程序(这里是你的 C# 绑定库)应该如何处理它们。