This is XML document:
<?xml version="1.0" encoding="utf-8" ?>
<ToolBars>
<ToolBarSet id="1" buttonsCounter="4" width="252">
<ToolBarItem id="1" Command="Command11" Icon="pic11" Enabled="true" Visible="true" />
<ToolBarItem id="2" Command="Command12" Icon="pic12" Enabled="true" Visible="true" />
<ToolBarItem id="3" Command="Command13" Icon="pic13" Enabled="true" Visible="true" />
<ToolBarItem id="4" Command="Command14" Icon="pic14" Enabled="false" Visible="true" />
</ToolBarSet>
<ToolBarSet id="2" buttonsCounter="2" width="170">
<ToolBarItem id="1" Command="Command21" Icon="pic11" Enabled="true" Visible="true" />
<ToolBarItem id="2" Command="Command22" Icon="pic22" Enabled="true" Visible="true" />
</ToolBarSet>
</ToolBars>
I want to fill the appropriate classes, this is my code:
("publics" are just for test)
class Program
{
static void Main(string[] args)
{
ToolBars test;
XmlSerializer mySerializer = new XmlSerializer(typeof(ToolBars));
using (FileStream myFileStream = new FileStream("c:\\XMLFile1.xml", FileMode.Open))
{
test = (ToolBars)mySerializer.Deserialize(myFileStream);
}
}
}
[Serializable]
[System.Xml.Serialization.XmlRoot("ToolBars")]
public class ToolBars
{
public int id;
public int buttonsCounter;
public int width;
[XmlArray("ToolBarSet")]
[XmlArrayItem("ToolBar", typeof(Toolbar))]
public List<Toolbar> toolbars = new List<Toolbar>();
}
[Serializable]
public class Toolbar
{
[XmlArray("ToolbarItem")]
[XmlArrayItem("ToolbarItem", typeof(ToolbarItem))]
public List<ToolbarItem> toolbarItems = new List<ToolbarItem>();
}
[Serializable]
public class ToolbarItem
{
public string command;
public int id;
public string icon;
public bool visible;
public bool enabled;
}
How to make it work?