シリアル化XMLに問題があり、それを噛む方法がわかりません。私のxmlファイルは次のようになります。
<?xml version="1.0" encoding="utf-8"?>
<ItemBag>
<Bag>
<BagConfig Name="txt" ZenDrop="0" ItemRate = "100" ExcRate="100" AncientRate="0" SocketRate="0"/>
</Bag>
<Default>
<DefaultConfig cat="1" id="1" minlv="0" maxlv="15" skill="1" luck="1" addopt="0" exc= "0" anc="0" sock="0" />
</Default>
<Items>
<Item cat="1" id="1" minlv="0" maxlv="15" skill="1" luck="1" addopt="0" exc="0" anc="0" sock="0" />
<Item cat="7" id="21" minlv="7" maxlv="7" skill="0" luck="0" addopt="0" exc="1" anc="0" sock="0" />
<Item cat="8" id="21" minlv="7" maxlv="7" skill="0" luck="0" addopt="0" exc="1" anc="0" sock="0" />
<Item cat="9" id="21" minlv="7" maxlv="7" skill="0" luck="0" addopt="0" exc="1" anc="0" sock="0" />
</Items>
</ItemBag>
これが私のSerializableクラスです:
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute()]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class ItemBag
{
public ItemBagBag Bag;
public ItemBagDefault Default;
[System.Xml.Serialization.XmlArrayItemAttribute("Item", IsNullable = true)]
public ItemBagItem[] Items;
}
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute()]
public partial class ItemBagBag
{
public ItemBagBagBagConfig BagConfig;
}
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute()]
public partial class ItemBagBagBagConfig
{
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Name;
[System.Xml.Serialization.XmlAttributeAttribute()]
public sbyte ZenDrop;
//.......ETC
}
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute()]
public partial class ItemBagDefault
{
public ItemBagDefaultDefaultConfig DefaultConfig;
}
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute()]
public partial class ItemBagDefaultDefaultConfig
{
[System.Xml.Serialization.XmlAttributeAttribute()]
public sbyte cat;
[System.Xml.Serialization.XmlAttributeAttribute()]
public sbyte id;
//........ETC
}
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute()]
public partial class ItemBagItem
{
[System.Xml.Serialization.XmlAttributeAttribute()]
public sbyte cat;
[System.Xml.Serialization.XmlAttributeAttribute()]
public sbyte id;
//.......ETC
}
これがSerializableメソッドです
static void SerializationToXml()
{
XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
namespaces.Add(string.Empty, string.Empty);
ItemBag item = new ItemBag()
{
Bag = new ItemBagBag
{
BagConfig = new ItemBagBagBagConfig
{ AncientRate = 1, ZenDrop = 1, ExcRate = 1, ItemRate = 1, Name = "ss", SocketRate = 1 }
},
Default = new ItemBagDefault
{
DefaultConfig = new ItemBagDefaultDefaultConfig
{ addopt = 1, anc = 1, cat = 1, exc = 1, id = 1, luck = 1, maxlv = 1, minlv = 1, skill = 1, sock = 1, Value = "1" }
},
Items = new ItemBagItem[]
{
//doesent work :(
}
};
TextWriter writer = new StreamWriter(@"c:\test.xml");
try
{
XmlSerializer serializer = new XmlSerializer(typeof(ItemBag));
serializer.Serialize(writer, item, namespaces);
writer.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
アイテムの配列を機能させる方法がわかりません(バッグとデフォルトの解析はOKです)私はあなたの助けを頼りにしています