How to deserialize an xml string

Nightvision

New Member
I was trying to deserialize an xml string and I am not getting deserialized the objects.My xml string looks like\[code\]<Cars> <Car> <Id>123445</Id> <BMW> <Id>78945</Id> </BMW> </Car></Cars>\[/code\]\[code\][Serializable()][XmlRoot("Cars")]public class Cars{ [XmlArrayItem("Car",typeof(Car))] public Car[] Car { get; set; }}[Serializable()]public class Car{ [XmlElement("Id")] public long Id { get; set; } [XmlArrayItem("BMW",typeof(BMW))] public BMW[] BMW { get; set; }}[Serializable()]public class BMW{ [XmlElement("Id")] public long Id { get; set; }}\[/code\]And this is the code I am trying:\[code\]string str = "xml string like above";XmlSerializer ser = new XmlSerializer(typeof(Cars));var wrapper = (Cars) ser.Deserialize(new StringReader(str));\[/code\]And I do have couple of sub array objects inside like BMW inside. BUt it is not serializing Car.Can someone please point out my mistake here?
 
Back
Top