Witam
Mam problem z wykonaniem Serializacji danych XML. Posiadam plik XML który zawiera "drzewo" główne i podkategorie w których są pozycje z kolejnymi w nich zagnieżdżonymi pozycjami danych i teraz chciałbym móc je odczytać do zmiennych w programie w którym utworzyłem plik Xml.cs w którym stworzyłem odpowiednie klasy i pola do pobrania tych danych w celu przypisania odczytanyh danych z pliku XML do tych zmiennych oraz klas. Pytanie i prośba o pomoc czy poprawnie to zrobiłem bo przy uruchomieniu programu dostaje błąd o długiej treści i nie wiem dlaczego i gdzie zrobiłem coś źle?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
namespace Segregacja
{
[XmlRoot("Document")]
public class Document
{
[XmlElement(ElementName = "PositionTopLeft")]
public int PositionTopLeft;
[XmlElement(ElementName = "Width")]
public int Width;
[XmlElement(ElementName = "Height")]
public int Height;
[XmlArray("Title")]
public Title[] Titles;
[XmlArray("BootleType")]
public BootleType[] BootleTypes;
[XmlArray("Shift")]
public Shift[] Shifts;
[XmlArray("DateTime")]
public DatesTime[] dateTimes;
}
public class DatesTime
{
[XmlElement(ElementName = "PosY")]
public int PosY;
}
public class Shift
{
[XmlElement(ElementName = "Title")]
public String Title;
[XmlElement(ElementName = "TitleNoNumber")]
public String TitleNoNumber;
[XmlElement(ElementName = "PosY")]
public int PosY;
[XmlArray("Number")]
public Number[] Numbers;
[XmlElement(ElementName = "DefaultOption")]
public int DefaultOption;
[XmlElement(ElementName = "DefaultChackedYesNoShift")]
public int DefaultCheckedYesNoShift;
}
public class Number
{
[XmlElement(ElementName = "Param")]
[XmlElement(IsNullable = false)]
public String[] Param = new String[50];
}
public class BootleType
{
[XmlElement(ElementName = "PosY")]
public int PosY;
[XmlArray("Item")]
public Item[] Items;
}
public class Item
{
[XmlElement(ElementName = "Param")]
[XmlElement(IsNullable = false)]
public String[] Param = new String[50];
}
public class Title
{
[XmlElement(ElementName = "PosY")]
public int PosY;
[XmlElement(ElementName = "Text")]
public String Text;
}
}
<?xml version="1.0" encoding="utf-8" ?>
<Document>
<PositionTopLeft>0</PositionTopLeft>
<Width>825</Width>
<Height>630</Height>
<Title>
<PosY>0</PosY>
<Text>TYTUŁ</Text>
</Title>
<BootleType>
<PosY>150</PosY>
<Item>
<Param>PIERWSZY</Param>
<Param>DRUGI</Param>
<Param>TRZECI</Param>
<Param>CZWARTY</Param>
<Param>PIĄTY</Param>
<Param>SZÓSTY</Param>
<Param>SIÓDMY</Param>
<Param>ÓSMY</Param>
<Param>DZIEWIĄTY</Param>
</Item>
</BootleType>
<Shift>
<Title>ZMIANA</Title>
<TitleNoNumber>ZMIANA ....</TitleNoNumber>
<PosY>330</PosY>
<Number>
<Param>I</Param>
<Param>II</Param>
<Param>III</Param>
</Number>
<DefaultOption>0</DefaultOption>
<DefaultCheckedYesNoShift>0</DefaultCheckedYesNoShift>
</Shift>
<DatesTime>
<PosY>530</PosY>
</DatesTime>
</Document>
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Document));
xmlSerializer.UnknownNode += new XmlNodeEventHandler(XmlSerializer_UnknownNode);
xmlSerializer.UnknownAttribute += new XmlAttributeEventHandler(XmlSerializer_UnknownAttribute);
StreamReader reader = new StreamReader(@XmlPath);
Document document = (Document)xmlSerializer.Deserialize(reader);
protected void XmlSerializer_UnknownNode(object sender, XmlNodeEventArgs e)
{
MessageBox.Show("Unknown Node:" + e.Name + "\t" + e.Text,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
protected void XmlSerializer_UnknownAttribute(object sender, XmlAttributeEventArgs e)
{
System.Xml.XmlAttribute attr = e.Attr;
MessageBox.Show("Unknown attribute " +
attr.Name + "='" + attr.Value + "'","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
Czemu nie wczytuje mi się to poprawnie gdzie mam błąd?