XML Serialize boolean as 0 and 1

前端 未结 3 1566
我在风中等你
我在风中等你 2020-12-20 11:11

The XML Schema Part 2 specifies that an instance of a datatype that is defined as boolean can have the following legal literals {true, false, 1, 0}. The following XML, for e

3条回答
  •  清歌不尽
    2020-12-20 11:31

    You can implement IXmlSerializable which will allow you to alter the serialized output of your class however you want. This will entail creating the 3 methods GetSchema(), ReadXml(XmlReader r) and WriteXml(XmlWriter r). When you implement the interface, these methods are called instead of .NET trying to serialize the object itself.

    Examples can be found at:

    http://www.developerfusion.co.uk/show/4639/ and

    http://msdn.microsoft.com/en-us/library/system.xml.serialization.ixmlserializable.aspx

提交回复
热议问题