【发布时间】:2016-03-28 18:45:06
【问题描述】:
我在 asp.net 5 控制器中以 xml 形式返回一个对象。该对象具有一个列表属性,我需要序列化程序忽略列表的根元素。我遵循了这篇文章的建议Use XML serialization to serialize a collection without the parent node,但由于某种原因它不起作用,如果我尝试使用 [XmlElement("newName")] 更改它的名称,它甚至会忽略它
任何线索为什么它可能会这样做?
public partial class Doc {
[XmlElement("Detalle")]
public List<DefTypeDetalle> Detalle { get; set; }
}
public partial class DefTypeDetalle {
public Id { get; set; }
}
我得到的输出
<Doc>
<Detalle>
<DefTypeDetalle>
<Id>1<Id/>
</DefTypeDetalle>
<DefTypeDetalle>
<Id>2<Id/>
</DefTypeDetalle>
</Detalle>
</Doc>
而我想要的是
<Doc>
<Detalle>
<Id>1<Id/>
</Detalle>
<Detalle>
<Id>2<Id/>
</Detalle>
</Doc>
谢谢
【问题讨论】:
-
我可以看到有问题的代码吗?
-
好的,我也添加了代码和xml
标签: c# xml asp.net-mvc xml-serialization