I have an XML structure like this:
<QueryResult>
<Submission>
<Sections>
<Section>
<!--Section Data-->
</Section>
</Sections>
</Submission>
</QueryResult>
I am trying to deserialize - I never have to serialize - this to a Submission object, e.g:
public partial class Submission : CanvasModel
{
private DateTime _date;
private DateTime _deviceDate;
private List<Section> _sections = new List<Section>();
[XmlIgnore]
public ICollection<Section> Sections
{
get
{
return _sections;
}
set
{
_sections = value.ToList();
}
}
//[XmlArrayItem("Section", IsNullable = false)]
[XmlArrayItem(typeof(Section), ElementName = "Sections", IsNullable = false)]
public Section[] SectionsArray
{
get
{
return _sections.ToArray();
}
set
{
_sections = new List<Section>(value);
}
}
}
Yet the XML element Sections is not deserializing. It only works when the Section[] property has the same name as the XML element, Sections. I am wrestling with the XmlArrayItem attribute and am losing. Elsewhere when the names differ, I use the XmlElement attribute to specify the element name, and everything works fine. However, I am not allowed to use XmlElement and XmlArrayItem on the same property.
What is the correct way for me to use the XmlArrayItem attribute to deserialize the Sections XML element to the SectionsArray property?
BTW, I want the widely used property, public ICollection<Section> Sections, that I need for my EF data model, to have the document name, Sections, for several reasons, so just swapping the two names is really my last resort. I want to keep the current SectionsArray property purely for deserialization.