【发布时间】:2009-07-29 05:30:40
【问题描述】:
我正在尝试序列化需要使用多个同名元素的自定义类。
我尝试过使用 xmlarray,但它将它们包装在另一个元素中。
我希望我的 xml 看起来像这样。
<root>
<trees>some text</trees>
<trees>some more text</trees>
</root>
我的代码:
[Serializable(), XmlRoot("root")]
public class test
{
[XmlArray("trees")]
public ArrayList MyProp1 = new ArrayList();
public test()
{
MyProp1.Add("some text");
MyProp1.Add("some more text");
}
}
【问题讨论】:
-
您是否尝试过设置属性 XmlArrayItem(typeof(System.String)) 以及 XMLArray ?
-
是的,它会在
下面创建类似 xml 的东西some text some more text -
好问题,坏标题。标题应为“如何使用 XmlSerializer 展平数组/列表/集合”
标签: c# .net xml-serialization