I have XML:
<?xml version="1.0" encoding="UTF-8"?> <gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01" xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref"> <gesmes:subject>Reference rates</gesmes:subject> <gesmes:Sender> <gesmes:name>European Central Bank</gesmes:name> </gesmes:Sender> <Cube> <Cube time='2015-12-16'> <Cube currency='USD' rate='1.0933'/> <Cube currency='JPY' rate='133.18'/> </Cube> </Cube> </gesmes:Envelope>
which I'm trying to deserialize with:
[XmlRoot("Envelope", Namespace = EcbNameSpace)] public class EcbEnvelope { const string EcbNameSpace = "http://www.gesmes.org/xml/2002-08-01"; [XmlElement("Sender", Namespace = EcbNameSpace)] public string EcbSender { get; set; } [XmlElement("subject", Namespace = EcbNameSpace)] public string EcbSubject { get; set; } [XmlArray("Cube")] [XmlArrayItem("Cube")] public List<CubeRoot> CubeRootEl { get; set; } public class CubeRoot { [XmlAttribute("time")] public string Time { get; set; } [XmlElement("Cube")] public List<CubeItem> CubeItems { get; set; } public class CubeItem { [XmlAttribute("rate")] public string RateStr { get; set; } [XmlIgnore] public decimal Rate { get { return decimal.Parse(RateStr); } } [XmlAttribute("currency")] public string Currency { get; set; } } } }
However, it deserializes CubeRootEl as empty list. If I remove namspaces from XML, then it deserializes successfully. What am I doing wrong? I tried adding empty namespaces to CubeRootEl in code, but also unsuccessfully.
No comments:
Post a Comment