I'm trying to deserialize the following XML:
<?xml version="1.0" encoding="utf-8" ?>
<mf:somedata xmlns:mf="urn:somedata">
<CurrentAccount>
<AccountType>test</AccountType>
<Charge>
<ChargeType>test</ChargeType>
</Charge>
</CurrentAccount>
<CurrentAccount>
<AccountType>test 2</AccountType>
<Charge>
<ChargeType>test 2</ChargeType>
</Charge>
</CurrentAccount>
</mf:somedata>
Using the following classes:
[XmlRoot("somedata", Namespace = "urn:somedata")]
public class MfCurrentAccounts
{
[XmlElement("CurrentAccount")]
public CurrentAccount[] CurrentAccounts { get; set; }
}
public class CurrentAccount
{
public string AccountType { get; set; }
[XmlElement("Charge")]
public Charge[] Charges { get; set; }
}
public class Charge
{
public string ChargeType { get; set; }
}
var c = new XmlSerializer(typeof(MfCurrentAccounts)).Deserialize(new StringReader(xml)) as MfCurrentAccounts;
c.CurrentAccounts // <-- is always null
But no matter what I try, the CurrentAccounts array is null when I deserialize it. I've tried every combination I can think of with the attributes (I've tried XmlArray and XmlArrayItem too).
What am I doing wrong? :S