我发现C的XML序列化有问题。序列化程序的输出在正常的win32和wince之间不一致(但令人惊讶的是wince有IMO校正器输出)。Win32只是忽略了Class2
XmlRoot("c2")
属性。
是否有人知道如何在win32上获得类似wince的输出(因为我不希望XML标记具有序列化类的类名)。
测试代码:
using System;
using System.Xml.Serialization;
using System.IO;
namespace ConsoleTest
{
[Serializable]
[XmlRoot("c1")]
public class Class1
{
[XmlArray("items")]
public Class2[] Items;
}
[Serializable]
[XmlRoot("c2")]
public class Class2
{
[XmlAttribute("name")]
public string Name;
}
class SerTest
{
public void Execute()
{
XmlSerializer ser = new XmlSerializer(typeof (Class1));
Class1 test = new Class1 {Items = new [] {new Class2 {Name = "Some Name"}, new Class2 {Name = "Another Name"}}};
using (TextWriter writer = new StreamWriter("test.xml"))
{
ser.Serialize(writer, test);
}
}
}
}
预期的XML(WinCE生成此文件):
<?xml version="1.0" encoding="utf-8"?>
<c1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<items>
<c2 name="Some Name" />
<c2 name="Another Name" />
</items>
</c1>
win32 xml(似乎是错误的版本):
<?xml version="1.0" encoding="utf-8"?>
<c1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<items>
<Class2 name="Some Name" />
<Class2 name="Another Name" />
</items>
</c1>