title: C# XML Serialization array and multiple class
body: <p>Ihave problem with serialization XML and dont know how to bite it.. 
  My xml file should look like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ItemBag&gt;
       &lt;Bag&gt;
           &lt;BagConfig Name="txt" ZenDrop="0" ItemRate = "100" ExcRate="100" AncientRate="0" SocketRate="0"/&gt;
       &lt;/Bag&gt;
       &lt;Default&gt;
           &lt;DefaultConfig cat="1" id="1" minlv="0" maxlv="15" skill="1" luck="1" addopt="0" exc= "0" anc="0" sock="0" /&gt;
       &lt;/Default&gt;
       &lt;Items&gt; 
           &lt;Item cat="1" id="1" minlv="0" maxlv="15" skill="1" luck="1" addopt="0" exc="0" anc="0" sock="0" /&gt;
           &lt;Item cat="7" id="21" minlv="7" maxlv="7" skill="0" luck="0" addopt="0" exc="1" anc="0" sock="0" /&gt;
           &lt;Item cat="8" id="21" minlv="7" maxlv="7" skill="0" luck="0" addopt="0" exc="1" anc="0" sock="0" /&gt;
           &lt;Item cat="9" id="21" minlv="7" maxlv="7" skill="0" luck="0" addopt="0" exc="1" anc="0" sock="0" /&gt;         
       &lt;/Items&gt; 
  &lt;/ItemBag&gt;
  </code></pre>
  
  <p>Here is my Serializable class:</p>
  
  <pre><code>[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
          }
  </code></pre>
  
  <p>Here is Serializable method</p>
  
  <pre><code>    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);
          }
  </code></pre>
  
  <p>I don't know how to make working an Array of Items (Bag and Default parsing OK)
  I count for Your help</p>