Reputation: 1790
I have some xml that i get from a service that looks like this
<Pools>
<Pool Code="WN" Name="Win" />
<Pool Code="PL" Name="Place" />
<Pool Code="SH" Name="Show" />
<Pool Code="EX" Name="Exacta" />
<Pool Code="PE" Name="Perfecta (Exacta)" />
</Pools>
I want to deserialize that into the following classes
public class Pools : List<Pool>
{
public Pools() { }
public Pools(int capacity) : base(capacity){ }
}
public class Pool
{
[XmlAttribute("Code")]
public string Code { get; set; }
[XmlAttribute("Name")]
public string Name { get; set; }
public Pool() {}
public Pool(string code, string name)
{
Code = code;
Name = name;
}
}
But it keeps failing and im not sure what im doing wrong... I have a feeling its an issue with the Pools class but im not sure what to apply to make it work
Thanks
Upvotes: 1
Views: 283
Reputation: 941218
Do this the other way around and you'll quickly find the problem. Your Pools class requires the [XmlRoot] attribute to ensure the element name isn't "ArrayOfPools".
[XmlRoot("Pools")]
public class Pools : List<Pool> {
// etc...
}
Upvotes: 2