我有一个继承的C#类。我已经成功“构建”了这个对象。但我需要将对象序列化为XML。有没有简单的方法来做到这一点?将对象序列化为XML
它看起来像类已设置了序列化,但我不知道如何让XML表示。我的类定义是这样的:
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.domain.com/test")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://www.domain.com/test", IsNullable = false)]
public partial class MyObject
{
...
}
这是我想我能做到,但它不工作:
MyObject o = new MyObject();
// Set o properties
string xml = o.ToString();
我如何获得此对象的XML表示?
我开发了一个简单的库做实现这一点:https://github.com/aishwaryashiva/SaveXML – 2015-08-28 14:03:51
另请参阅:XML序列化和反序列化在CodeProject](http://www.codeproject.com/Articles/487571/XML-Serializ通货膨胀-和反序列化-部分) – 2014-09-14 14:59:19