我在 C# VS2003 / .Net 1.1 应用程序中序列化一个对象。但是,我需要在没有处理指令的情况下对其进行序列化。XmlSerializer 类输出如下内容:
<?xml version="1.0" encoding="utf-16" ?>
<MyObject>
<Property1>Data</Property1>
<Property2>More Data</Property2>
</MyObject>
有没有办法得到类似下面的东西,而不处理结果文本来删除标签?
<MyObject>
<Property1>Data</Property1>
<Property2>More Data</Property2>
</MyObject>
对于那些好奇的人,我的代码看起来像这样......
XmlSerializer serializer = new XmlSerializer(typeof(MyObject));
StringBuilder builder = new StringBuilder();
using ( TextWriter stringWriter = new StringWriter(builder) )
{
serializer.Serialize(stringWriter, comments);
return builder.ToString();
}