class Program
{
static void Main(string[] args)
{
XElement test = XDocument.Parse(File.ReadAllText(@"C:\test.xml")).Root;
var tt = Panel.Deserialize(test);
}
}
[XmlRoot(ElementName = "panel")]
public class Panel
{
public int PanelId { get; set; }
public string Description { get; set; }
[XmlArray(ElementName="tr")]
[XmlArrayItem(ElementName="td")]
public List<tr> Tr { get; set; }
public XElement Serialize()
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Panel));
MemoryStream ms = new MemoryStream();
xmlSerializer.Serialize(ms, this);
ms.Seek(0, SeekOrigin.Begin);
return XElement.Load(ms);
}
public static Panel Deserialize(XElement BaseXML)
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Panel));
MemoryStream ms = new MemoryStream();
BaseXML.Save(ms);
ms.Seek(0, SeekOrigin.Begin);
var t = xmlSerializer.Deserialize(ms) as Panel;
return t;
}
}
public class Element
{
public int ElementId { get; set; }
}
public class tr
{
[XmlArray(ElementName="tr")]
[XmlArrayItem(ElementName="td")]
public List<td> td { get; set; }
}
public class td
{
public Element Element { get; set; }
} |