当值与默认值相同时包含 xml 属性 [英] Including xml attribute when the value is the same as the default
本文介绍了当值与默认值相同时包含 xml 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 xsd,我们使用 .net 中的 XMLSerializer 类来生成 xml 文档.我们有以下类型,默认值
i have an xsd we use with the XMLSerializer class in .net to generte an xml document. We have the following type with a default value
<xs:complexType name="telephoneType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="type" default="BH">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="BH"/>
<xs:enumeration value="AH"/>
<xs:enumeration value="mobile"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
当我们将值设置为默认值 BH 时,它似乎不包含文档中的属性.有没有办法总是包含这些?
It seems like when we set the value to BH which is the default it does not include the attribute in the document. is there a way to always include these?
推荐答案
当属性等于其默认值时,序列化器将不会创建元素/属性.除非您创建自定义方法来序列化您的对象,否则几乎没有什么可做的.
The serialiser will not create the element/attribute when the property is equal to its default value. There is going to be little to do unless you create a custom method to serialize your objects.
这篇关于当值与默认值相同时包含 xml 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文