I currently have a structure as such
[XmlRoot("command")]
public class Command
{
[XmlArray("itemlist")]
[XmlArrayItem("item")]
public List<Item> Items { get; set; }
}
[XmlRoot("item")]
public class Item
{
[XmlAttribute("itemid")]
public string ItemID { get; set; }
}
which works great for it's purpose, but given this xml
<command>
<itemlist totalsize="999">
<item itemid="1">
<item itemid="2">
...
</itemlist>
</command>
how do I get totalsize from itemlist when deserializing?
The XML is something I receive and is not something i can control.
I'm not looking for GetAttributeValue or similar, but purely using xmlserializer
You need to split
itemlistanditeminto two classes.As an aside, note that an
XmlRootattribute is only relevant on the root element. The one you have onItemis ignored in this instance.