XML 序列化 - 多个元素同名
XML Serialization - Multiple Elements Same Name
使用 C#,我试图将 XML 序列化为这个字符串:
<root>
<IncludeRetElement>TxnID</IncludeRetElement>
<IncludeRetElement>TimeCreated</IncludeRetElement>
<IncludeRetElement>TimeModified</IncludeRetElement>
<IncludeRetElement>EditSequence</IncludeRetElement>
<IncludeRetElement>TxnNumber</IncludeRetElement>
<IncludeRetElement>CustomerRef</IncludeRetElement>
</root>
我的 class 应该是什么样子?我认为这行不通:
public class Root
{
List<string> IncludeRetElement = new List<string>();
}
序列化时,是否需要向 XMLSerializer 对象添加特殊参数?
这应该有效:
[XmlElement("IncludeRetElement")]
public string[] IncludeRetElement { get; set; }
使用 C#,我试图将 XML 序列化为这个字符串:
<root>
<IncludeRetElement>TxnID</IncludeRetElement>
<IncludeRetElement>TimeCreated</IncludeRetElement>
<IncludeRetElement>TimeModified</IncludeRetElement>
<IncludeRetElement>EditSequence</IncludeRetElement>
<IncludeRetElement>TxnNumber</IncludeRetElement>
<IncludeRetElement>CustomerRef</IncludeRetElement>
</root>
我的 class 应该是什么样子?我认为这行不通:
public class Root
{
List<string> IncludeRetElement = new List<string>();
}
序列化时,是否需要向 XMLSerializer 对象添加特殊参数?
这应该有效:
[XmlElement("IncludeRetElement")]
public string[] IncludeRetElement { get; set; }