【问题标题】:XML Serialization - Multiple Elements Same NameXML 序列化 - 多个元素同名
【发布时间】:2015-03-28 02:24:37
【问题描述】:

使用 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 对象添加特殊参数?

【问题讨论】:

    标签: xml serialization


    【解决方案1】:

    这应该可行:

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

    【讨论】:

      猜你喜欢
      • 2011-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-14
      相关资源
      最近更新 更多