Kód: Vybrať všetko
A first chance exception of type 'System.InvalidOperationException' occurred in System.Xml.dll
Kód: Vybrať všetko
public class NCdata
{
private string filename = "NCdata.xml";
[XmlElement("Brand")]
public List<Brand> brands = new List<Brand>();
public Car one_car = new Car();
public bool Save()
{
if (brands.Count == 0) return false;
System.Diagnostics.Debug.Write("Start serialiazatin\n");
XmlSerializer serializer = new XmlSerializer(typeof(List<Brand>));
FileStream fs = File.OpenWrite(filename);
XmlTextWriter writer = new XmlTextWriter(fs,System.Text.Encoding.UTF8);
writer.Formatting = Formatting.Indented;
//TextWriter textWriter = new StreamWriter(filename);
try
{
serializer.Serialize(writer, brands);
}
finally
{
writer.Close();
}
System.Diagnostics.Debug.Write("Serization complet\n");
return true;
}Kód: Vybrať všetko
[Serializable]
public class Brand
{
public string name;
[XmlElement("Model")]
public List<Model> models = new List<Model>();
[XmlElement("Engine")]
public List<Engine> engines = new List<Engine>();
public Brand(string name)
{
this.name = name;
}
public string GetName
{
get { return name; }
}
}