XML序列化 - 多个元素同名

时间:2015-03-28 02:24:37

标签: xml serialization

使用C#,我试图将XML序列化为这个字符串:

<root>
            <IncludeRetElement>TxnID</IncludeRetElement>
            <IncludeRetElement>TimeCreated</IncludeRetElement>
            <IncludeRetElement>TimeModified</IncludeRetElement>
            <IncludeRetElement>EditSequence</IncludeRetElement>
            <IncludeRetElement>TxnNumber</IncludeRetElement>
            <IncludeRetElement>CustomerRef</IncludeRetElement>

</root>

我的课程必须是什么样的?我不相信这会奏效:

 public class Root
 {
     List<string> IncludeRetElement = new List<string>();
 }

当我序列化时,是否需要向XMLSerializer对象添加特殊参数?

1 个答案:

答案 0 :(得分:4)

这应该有效:

[XmlElement("IncludeRetElement")]
public string[] IncludeRetElement { get; set; }