Hello
I have a XML, like this(there could be many more Message elements):
- <xml version="1.0" encoding="utf-8"?>
- <response>
- <Count>2Count>
- <Messages>
- <Message>
- <Smstat>0Smstat>
- <Index>40005Index>
- <Phone>+4xxxxxxPhone>
- <Content>Test 2Content>
- <Date>2019-12-08 18:13:35Date>
- <Sca>Sca>
- <SaveType>4SaveType>
- <Priority>0Priority>
- <SmsType>1SmsType>
- Message>
- <Message>
- <Smstat>1Smstat>
- <Index>40004Index>
- <Phone>+4xxxxxx>
- <Content>Test 1Content>
- <Date>2019-12-08 18:13:30Date>
- <Sca>Sca>
- <SaveType>4SaveType>
- <Priority>0Priority>
- <SmsType>1SmsType>
- </Message>
- </Messages>
- </response>
I'd like to deserialize it, I came up with this code:
- [Serializable()]
- [System.Xml.Serialization.XmlRoot("Messsages")]
- public class Messsages
- {
- [XmlArray("Messsages")]
- [XmlArrayItem("Message", typeof(Message))]
- public Message[] Car { get; set; }
- }
- [Serializable()]
- public class Message
- {
- [System.Xml.Serialization.XmlElement("Smstat")]
- public int Smstat { get; set; }
-
- [System.Xml.Serialization.XmlElement("Index")]
- public int Index { get; set; }
-
- [System.Xml.Serialization.XmlElement("Phone")]
- public string Phone { get; set; }
-
- [System.Xml.Serialization.XmlElement("Content")]
- public string Content { get; set; }
-
- [System.Xml.Serialization.XmlElement("Date")]
- public string Date { get; set; }
-
- [System.Xml.Serialization.XmlElement("sca")]
- public string sca { get; set; }
-
- [System.Xml.Serialization.XmlElement("SaveType")]
- public string SaveType { get; set; }
-
- [System.Xml.Serialization.XmlElement("Priority")]
- public string Priority { get; set; }
-
- [System.Xml.Serialization.XmlElement("SmsType")]
- public string SmsType { get; set; }
- }
- Messsages[] messages = null;
- XmlSerializer serializer = new XmlSerializer(typeof(Message[]));
-
- using (var response = (HttpWebResponse)request.GetResponse())
- {
- messages = (Messsages[])serializer.Deserialize(response.GetResponseStream());
- }
If I do it like this I get an InvalidOperationException telling me that the xml doesn't match due to the "response"
If I have a look on my XML the Messages are inside "" - so far it makes sense.
My question now is, how can I "ignore" that "response"? It is unneeded information for me and I just like to finally have only the data that I defined in the two data classes above.
Is there some ignore flag or how could I achieve that?
Thank you for your help!