I have the following XML
<map version="1.0">
<properties>
<property name="color" value="blue" />
<property name="size" value="huge" />
<property name="texture" value="rugged" />
</properties>
</map>
I am trying to write classes that I can deserialize this into, this is what I have:
[XmlRoot("map")]
public class MyMap
{
[XmlAttribute("version")]
public decimal Version { get; set; }
[XmlElement("properties")]
public List<MyProperty> Properties { get; set; }
}
public class MyProperty
{
[XmlAttribute("name")]
public string Name { get; set; }
[XmlAttribute("value")]
public string Value { get; set; }
}
The problem is that I cant seem to read the property list, I just get one entry and it has null in both Name and Value.
Are there some magic attributes I need to set to get this to work?
You should change MyMap as below. XmlArray
and XmlArrayItem
are the magic attributes
[XmlRoot("map")]
public class MyMap
{
[XmlAttribute("version")]
public decimal Version { get; set; }
[XmlArray("properties")]
[XmlArrayItem("property")]
public List<MyProperty> Properties { get; set; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With