I have an XML Structure that should really have been an array, but is not structured this way. Here is a representation of the XML.
<rootElement>
<foo>...</foo>
<bar>...</bar>
<bar>...</bar>
<bar>...</bar>
</rootElement>
I cant seem to get <bar>
to turn into an array. I have the following C# class to try and do this.
[XmlRoot("rootElement")]
public class MyClass
{
[XmlArrayItem("bar")]
public List<MyItems> Items { get; set; }
}
It doesnt work though. I know I could parse the XML using an XML Document and then convert it to a C# object this way but i would rather just use attributes on the C# class and quickly generate the object using XmlSerializer.
I have tried using a variation of attributes on the Items property such as XmlElement and XmlArray but i keep getting 0 items after deserializing. Is there a way this can be done using the XmlSerializer or do i have no other alternative than to use XmlDocument?