将XML反序列化为对象:具有xsi:nil =“true”的XML元素对于对象中的相应属性应该具有空值(而非空值)
问题描述:
将以下XML解序列化为父类时,ElementTwo和ElementThree是空串,这是预期的。但是ElementOne应该是null,但是它也是空字符串。将XML反序列化为对象:具有xsi:nil =“true”的XML元素对于对象中的相应属性应该具有空值(而非空值)
XML
<?xml version = \"1.0\" ?>
<Parent
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ElementOne xsi:nil="true"/>
<ElementTwo></ElementTwo>
<ElementThree />
<ElementFour>Value</ElementFour>
</Parent>
C#类
public class Parent
{
public string ElementOne { get; set; }
public string ElementTwo { get; set; }
public string ElementThree { get; set; }
public string ElementFour { get; set; }
}
当解串行化XML到对象,具有的xsi XML元素:无=”真“不会被转换为空。相反,它被分配为空字符串。但我有一个要求,它应该被转换为null只。请帮我找出一个解决方案或点放在哪里出了错
我已经给下面拨弄链接中使用的样本: