I have the following class structure I want to serialize to XML:
public class Foo
{
[XmlArray("approxPriceList")]
[XmlArrayItem("approxPrice")]
public List<ApproxPriceElement> ApproxPriceList { get; set; }
}
public class ApproxPriceElement
{
[XmlAttribute("currency")]
public string Currency { get; set; }
[XmlElement("approxPrice")]
public decimal? ApproxPrice { get; set; }
}
If I serialize Foo, I get the following XML:
<approxPriceList>
<approxPrice currency="aud">
<approxPrice>2220.00</approxPrice>
</approxPrice>
</approxPriceList>
What I want is the following:
<approxPriceList>
<approxPrice currency="aud">2220.00</approxPrice>
</approxPriceList>
One thought was to change ApproxPriceList in Foo to be a List<decimal?> but then I can't figure out how to associate a currency attribute with each approxPrice in the list.
Is there a way to achieve this?