I'm trying to parse a xml file in an object
This is my xml file named Changelog.xml
<?xml version="1.0" encoding="utf-8" ?>
<Changelog>
<Releases>
<Release>
<Version>1507</Version>
<Date>22-11-2013</Date>
<Changes>
<Change>Change1</Change>
<Change>Change2</Change>
<Change>Change3</Change>
<Change>Change4</Change>
</Changes>
</Release>
<Release>
<Version>1506</Version>
<Date>20-11-2013</Date>
<Changes>
<Change>Change1</Change>
</Changes>
</Release>
</Releases>
</Changelog>
This is my Changelog object I want to cast the xml to
[XmlRoot()]
public class Changelog
{
private List<Release> releases;
public List<Release> Releases
{
get { return releases; }
set { releases = value; }
}
}
public class Release
{
private string version;
private string date;
private List<ChangeItem> changes;
[XmlElement]
public string Version
{
get { return version; }
set { version = value; }
}
[XmlElement]
public string Date
{
get { return date; }
set { date = value; }
}
[XmlElement]
public List<ChangeItem> Changes
{
get { return changes; }
set { changes = value; }
}
}
public class ChangeItem
{
private string change;
[XmlElement]
public string Change
{
get { return change; }
set { change = value; }
}
}
Here I read the file
XmlSerializer serializer = new XmlSerializer(typeof(Changelog));
Changelog changelog = (Changelog)serializer.Deserialize(new StreamReader(@"changelog.xml"));
Releases = changelog.Releases;
foreach (Release release in Releases)
{
string version = release.Version;
string date = release.Date;
List<ChangeItem> changes = release.Changes; // Has only 1 item
}
The problem is that there is only 1 object in the Changes list, altough I expect 4 for the 1507 release.
What am I doing wrong?