我正在尝试反序列化以下 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>
使用以下类:
[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
但是无论我尝试什么,当我反序列化 CurrentAccounts 数组时它都是空的。我已经尝试了所有我能想到的属性组合(我也尝试过 XmlArray 和 XmlArrayItem)。
我究竟做错了什么?:S