【发布时间】:2016-09-01 14:32:04
【问题描述】:
我有以下 XML:
<Line id="6">
<item type="product" />
<warehouse />
<quantity type="ordered" />
<comment type="di">Payment by credit card already received</comment>
</Line>
在 .NET(2010 使用 C#)中序列化对象时,有没有办法不输出未设置的元素?在我的情况下,item type、warehouse、quantity 以便在序列化时得到以下结果:
<Line id="6">
<comment type="di">Payment by credit card already received</comment>
</Line>
我在 XmlElement 或 XmlAttribute 中看不到任何可以让我实现此目的的属性。
是否需要 XSD?如果是,我会怎么做?
【问题讨论】:
-
在上面的例子中,
item和quantitydo 有值...
标签: c# xml serialization xml-serialization