I'm having a bit of a head scratching moment here, as I think I'm doing this correctly! I need to create an xml file as below, (I've left out the namespace declarations)
<races>
<race racename="race one">
<horse>
<name>Silver</name>
<age>6</name>
</horse>
</race>
</races>
Class races is a collection of class race, and class race is a collection of class horse. Below is the relevant code for race class which I have and is causing the problem (I think at least).
[Serializable]
[XmlType("race")]
public class Race : CollectionBase
{
private string _raceName;
[XmlAttribute("racename")]
public string RaceName
{
get
{
return this._raceName;
}
set
{
this._raceName = value;
}
}
I have the xml file building as expected EXCEPT the attribute racename is not being serialized. It is definitely being assigned to the race object before serialization. Any thoughts? I'm obviously missing something somewhere but I'm not sure how I'd even test where it's failing. Any help would be greatly appreciated!
Eoin.