質問
この問題は、XMLを直列化のC#.の出力をシリアライザが不間通常のWin32とWinCEが意外とWinCEをIMO correcterしやすくなります。Win32では最大クラス2 XmlRoot("c2")
属性。
なんだろうけど、日本人の方からのWinCEのように出力またはWin32(壊してしまうことを意味している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>
Win32XML(そうな間違った版)
<?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>
解決
み[XmlArrayItem("c2")]
[XmlRoot("c1")]
public class Class1
{
[XmlArray("items")]
[XmlArrayItem("c2")]
public Class2[] Items;
}
【XmlType("c2")]
[XmlType("c2")]
public class Class2
{
[XmlAttribute("name")]
public string Name;
}
所属していません StackOverflow