【发布时间】:2011-07-13 11:28:21
【问题描述】:
我一直在研究 xml 序列化,但在序列化列表集合时遇到了问题。我想序列化一个列表集合,而不用上层元素环绕它。请参见下面的示例:
结果序列化:
<?xml version="1.0" encoding="utf-8" ?>
<Person>
<Name>John</Name>
<AddressLine>
<string>Line 1</string>
<string>Line 2</string>
<string>Line 3</string>
</AddressLine>
<Telephone>123456789</Telephone>
</Person>
我要输出的序列化是:
<?xml version="1.0" encoding="utf-8" ?>
<Person>
<Name>John</Name>
<AddressLine>Line 1</AddressLine>
<AddressLine>Line 2</AddressLine>
<AddressLine>Line 3</AddressLine>
<Telephone>123456789</Telephone>
</Person>
我已经尝试为我要序列化的类设置不同的属性,但我似乎无法使用它。如果有人能告诉我我需要使用哪些属性来使我的 xml 序列化看起来像我想要的输出 xml,那将不胜感激。
干杯!
【问题讨论】:
标签: c# .net xml serialization xml-serialization