I have to deserialize the following XML received from a provider
<desc> <l_error> <error>Error 1</error> <error>Error 2</error> </l_error> </desc>
To do I I'm using DataContractSerializer, I have defined the following classes to deserialize it
[CollectionDataContract(Name = "desc", Namespace = "")] public class DescriptionError : List<Error> { } [DataContract(Name = "l_error", Namespace = "")] public class Error { [DataMember(Name = "error")] public string Description { get; set; } }
And a generic method do deserialize
public static T Deserialize<T>(string text) { using (MemoryStream stream = text.ToStream()) { var serializer = new DataContractSerializer(typeof(T)); return (T)serializer.ReadObject(stream); } }
The problem is when I Deserialize the above XML the DescriptionError object returned only contains one element, the first "error 1" ,the second error item in the XML is not in DescriptionError. I'm not able to figure what I'm doing wrong.
Thanks.
No comments:
Post a Comment