尝试将来自供应商的一些XML片段反序列化为对象,但问题在于每个空元素标签上都会获得无效格式的错误。当所有元素都具有值时,我可以轻松地反序列化对象;或者省略空元素。
XML片段:
<foo>
<propOne>1</propOne>
<propTwo />
</foo>
C#类:
[Serialilbe()]
public class foo
{
public foo(){}
[XmlElementAttribute(IsNullable = true)]
public int? propOne {get;set;}
[XmlElementAttribute(IsNullable = true)]
public int? propTwo {get;set;}
}
我可以在类上设置什么参数来调整解析吗?
或者
有没有一种简单的方法可以应用xsl来删除这些元素?
或者
我应该使用正则表达式在反序列化之前删除空元素吗?
或者
是否有更好的方法?