问题
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>
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?
回答1:
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.
来源:https://stackoverflow.com/questions/11857274/including-xml-attribute-when-the-value-is-the-same-as-the-default