0

I apologize in advance if this question has already been asked, but I could not find anything that could help me understand how to solve the problem.

The thing is, when trying to deserialize a camt54 of a particular bank, my procedure goes wrong. Investigating the problem I realized that the desrializer fails to convert this tag:

<ToDtTm>2020-11-18T24:00:00+01:00</ToDtTm>
    

Obviously I understand why. The C # datetime format does not include 24:00:00 and the debugger returns the error: "The string '2020-11-18T24:00:00+01:00' is not a valid AllXsd value"

But from what I understand in xml it is an accepted value.

Unfortunately this is the first case that happens to me. I have deserialized a lot of camt54 and have never had any problems until now.

How can I tell the deserializer to correctly read the value inserted in the xml?

Thank you in advance. Matteo.

matsnake86
  • 13
  • 3

1 Answers1

1

Use following :

    class Program
    {
        static void Main(string[] args)
        {
            string xml = "<root><ToDtTm>2020-11-18T24:00:00+01:00</ToDtTm></root>";
            StringReader sReader = new StringReader(xml);
            XmlReader xReader = XmlReader.Create(sReader);
            XmlSerializer serializer = new XmlSerializer(typeof(root));
            root root = (root)serializer.Deserialize(xReader);
        }
    }
    public class root
    {
        public DateTime _ToDtTm { get; set; }
        public String ToDtTm {
            get {
                return _ToDtTm.ToString(@"yyyy-MM-dd\Thh:mm:sszzz"); 
            }
            set {
                string date = value.Replace("T24", "T00");
                _ToDtTm = DateTime.Parse(date); }
            }
    }
jdweng
  • 33,250
  • 2
  • 15
  • 20