Importing XML to List C#



I have a Problem using Linq and Lists...


I have this code:



class CalendarItemList : System.Collections.Generic.List<CalendarItem>
{
public void Load(string FileName)
{
XDocument xdoc = XDocument.Load(FileName);

Console.WriteLine("Dokument geladen...");

foreach (XElement xEl in xdoc.Root.Elements())
{
this.Add(new CalendarItem(xEl));
}
}
}


And this other Class:



namespace XMLDeserialize
{
[Serializable]
public class CalendarItem : List<CalendarItemList>
{

//Here is the Point where the List should be filled with all my XElements

public CalendarItem(XElement xEl)
{
foreach (XElement xElChild in xEl.Elements())
{
initFromElement(xEl);
}
}

private void initFromElement(System.Xml.Linq.XElement x)
{

if (x.Name == "Value")
{
m_Value = x.Value;
return;
}
if (x.Name == "Key")
{
int.TryParse(x.Value, out m_Key);
return;
}
}


But yet I didn't got my XML File entries in my List. Could you please help me?


No comments:

Post a Comment