Deserialize Xml with empty elements in C#

后端 未结 4 796
醉梦人生
醉梦人生 2020-12-01 21:16

Trying to deserialize some xml snippits from a vendor into objects. The problem is that I\'m getting an invalid format on every empy element tag. I can deserialize the obj

4条回答
  •  日久生厌
    2020-12-01 21:31

    See this article: Can XmlSerializer deserialize into a Nullable?

    In a nutshell your Xml should look like this if you want to use Nullable types:

    
    1
    
    
    

    The two changes are adding the namespace, and explicitly setting xsi:nil to true on the null element.

    If you don't have control over your Xml there is a more advanced technique described here: Using XmlSerializer to deserialize into a Nullable

提交回复
热议问题