0

I have a .NET Core API which accepts the XML as Input and it has a complex type and my Model is having a simple property for that, on deserialization API is giving error. Sample XML is

<Message>
   <EffectiveDate>
      <Date>11/13/2020</Date>
   </EffectiveDate>
</Message>

and the Model looks like

  [XmlRoot(ElementName = "Message")]
    public class MyClass
    {
        [XmlElement(ElementName = "Date")]
        public DateTime EffectiveDate { get; set; }
    }
  

Is there any way to handle this without creating the EffectiveDate wrapper class like

 [XmlRoot(ElementName = "Message")]
    public class MyClass
    {
        [XmlElement(ElementName = "EffectiveDate")]
        public EffectiveDate EffectiveDate { get; set; }
    }

    [XmlRoot(ElementName = "EffectiveDate")]
    public class EffectiveDate
    {
        [XmlElement(ElementName = "Date")]
        public DateTime Date { get; set; }
    }

Can anyone help me with this problem? I can not change the XML since it is coming from some other application and there are many elements wrapped like this so looking for a way to have Model without an extra wrapper class

Nithya
  • 582
  • 8
  • 19

0 Answers0