i have the following xml structure im trying to deserialize into a c# object:
<leagueTable>
<competition>Calor League Division One Central</competition>
<description>League Table</description>
<team>
<position>1</position>
<name>Barton Rovers</name>
<played>13</played>
<won>8</won>
<drawn>3</drawn>
<lost>2</lost>
<for>25</for>
<against>16</against>
<goalDifference>+9</goalDifference>
<points>27</points>
</team>
<team>
......
</team>
<team>
.....
</team>
</leagueTable>
and have created two classes for them to be deserialized into which are as follows
public class leagueTable
{
public string competition { get; set; }
public string description { get; set; }
[XmlElement("team")]
public List<team> TeamsList { get; set; }
}
and
[Serializable()]
public class team
{
public int position { get; set; }
public String name { get; set; }
public int played { get; set; }
public int won { get; set; }
public int drawn { get; set; }
public int lost { get; set; }
[XmlElement("for")]
public int goalsfor { get; set; }
[XmlElement("against")]
public int goalsagainst { get; set; }
[XmlElement("goalDifference")]
public int goaldifference { get; set; }
public int points { get; set; }
}
What i cant seem to figure out is how to get the teams deserialized into a list object. When the deserialization happens the competition and description properties are populated, however the teamslist list object is null. i have tried a number of different ways to create the property but each either fail or just stay as null. I have followed a number of different posts on here and on the web but no matter what i try it still fails to be populated.
For completeness this is the deserialisation code, edited to show xml setting
XmlSerializer serializer = new XmlSerializer(typeof(leagueTable));
leagueTable league = null;
Stream xmldoc = response.GetResponseStream();
XmlReaderSettings xmlsettings = new XmlReaderSettings();
xmlsettings.DtdProcessing = DtdProcessing.Parse;
using (XmlReader reader = XmlReader.Create(xmldoc, xmlsettings))
{
league = (leagueTable)serializer.Deserialize(reader);
}