XML Deserialization issue with Array element
In order to specify the XML element names of an array (IList
, ICollection
, etc.) and it's items, you have to use the attributes XmlArray
and XmlArrayItem
:
[Serializable, XmlRoot("person")]public class FooUserProfile{ /* The other members... */ [XmlArray("positions")] [XmlArrayItem("position")] public List<FooPosition> Positions { get; set; }}
The attribute XmlElement
has the effect that the surrounding XML array element will be omitted and give the Xml array items it's names:
[XmlRoot("Config")]public class Foo{ [XmlElement("Id")] public string[] IdStringArrayWithStupidName;}
Serialized XML:
<?xml version="1.0" encoding="?><Config> <Id></Id> <Id></Id></Config>