【发布时间】:2014-11-24 15:36:01
【问题描述】:
我正在尝试使用 XmlSerializer 类将这样的类序列化为 xml:
public class Car {
public InsuranceData Insurance { get; set; } // InsuranceData is a class with many properties
public int Person Owner { get; set; }
public int Age { get; set; }
public string Model { get; set; }
// lots of other properties...
}
我想在 xml 文档的最后添加 Insurance 属性:
<Car>
...
<Insurance>
...
</Insurance>
</Car>
我需要这样做,因为处理 xml 的服务器只能在此布局中正常工作(而且我无法更改服务器代码)。 我尝试将属性移动到类的末尾,但这没有任何区别,而且我没有找到任何与序列化相关的属性会有所帮助。 我可以通过将 xml 操作为字符串来解决这个问题,但我更喜欢更优雅的解决方案。对象有很多属性,所以我不想手动创建 xml 字符串。
【问题讨论】:
-
也许你会在这个question找到答案
标签: c# .net xml serialization xmlserializer