Including xml attribute when the value is the same as the default

烂漫一生 提交于 2019-12-11 17:28:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!