Deserialize XML into Class

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Im trying to deserialize my an XDocument into a Class, but I am tripping up in the following line:
<span style="font-size:small <span style="font-size:small <span style="font-size:small <span style="font-size:small
<pre class="prettyprint prettyprinted <span class="pln collectiondeliveryresponse <span class="pun =<span class="pln <span class="pun (<span class="typ DeliveryResponse<span class="pun )<span class="pln serializer<span class="pun .<span class="typ Deserialize<span class="pun (<span class="pln sr<span class="pun ); [/code]

Here is my XML which may contain any number of Recipient_Status Child Nodes:
<pre class="prettyprint prettyprinted <span class="tag <TELEMESSAGE><span class="pln
<span class="tag <TELEMESSAGE_CONTENT><span class="pln
<span class="tag <MESSAGE_STATUS><span class="pln
<span class="tag <STATUS_ID></STATUS_ID><span class="pln
<span class="tag <STATUS_DESCRIPTION></STATUS_DESCRIPTION><span class="pln
<span class="tag <MESSAGE_ID><span class="pln 75587<span class="tag </MESSAGE_ID><span class="pln
<span class="tag <RECIPIENT_STATUS><span class="pln
<span class="tag <RECIPIENT_NAME></RECIPIENT_NAME><span class="pln
<span class="tag <DEVICE><span class="pln
<span class="tag <TYPE><span class="pln 40<span class="tag </TYPE><span class="pln
<span class="tag <VALUE><span class="pln abc<span class="tag </VALUE><span class="pln
<span class="tag <STATUS><span class="pln 1100<span class="tag </STATUS><span class="pln
<span class="tag <DESCRIPTION><span class="pln Email was delivered<span class="tag </DESCRIPTION><span class="pln
<span class="tag <STATUS_DATE><span class="pln 20130117 22:41:12<span class="tag </STATUS_DATE><span class="pln
<span class="tag </DEVICE><span class="pln
<span class="tag </RECIPIENT_STATUS><span class="pln
<span class="tag <RECIPIENT_STATUS><span class="pln
<span class="tag <RECIPIENT_NAME></RECIPIENT_NAME><span class="pln
<span class="tag <DEVICE><span class="pln
<span class="tag <TYPE><span class="pln 60<span class="tag </TYPE><span class="pln
<span class="tag <VALUE><span class="pln 21355<span class="tag </VALUE><span class="pln
<span class="tag <STATUS><span class="pln 1500<span class="tag </STATUS><span class="pln
<span class="tag <DESCRIPTION><span class="pln SMS successfully sent<span class="tag </DESCRIPTION><span class="pln
<span class="tag <STATUS_DATE><span class="pln 20130117 22:41:13<span class="tag </STATUS_DATE><span class="pln
<span class="tag </DEVICE><span class="pln
<span class="tag </RECIPIENT_STATUS><span class="pln
<span class="tag <RECIPIENT_STATUS><span class="pln
<span class="tag <RECIPIENT_NAME></RECIPIENT_NAME><span class="pln
<span class="tag <DEVICE><span class="pln
<span class="tag <TYPE><span class="pln 10<span class="tag </TYPE><span class="pln
<span class="tag <VALUE><span class="pln 50621<span class="tag </VALUE><span class="pln
<span class="tag <STATUS><span class="pln 3000<span class="tag </STATUS><span class="pln
<span class="tag <DESCRIPTION><span class="pln Message delivery in progress<span class="tag </DESCRIPTION><span class="pln
<span class="tag <STATUS_DATE><span class="pln 20130117 22:41:11<span class="tag </STATUS_DATE><span class="pln
<span class="tag </DEVICE><span class="pln
<span class="tag </RECIPIENT_STATUS><span class="pln
<span class="tag </MESSAGE_STATUS><span class="pln
<span class="tag </TELEMESSAGE_CONTENT><span class="pln
<span class="tag <VERSION><span class="pln 1<span class="tag </VERSION><span class="pln
<span class="tag </TELEMESSAGE>[/code]

Here is my public class, where I believe the problem to be:
<pre class="prettyprint prettyprinted <span class="pln <span class="kwd public<span class="pln <span class="kwd class<span class="pln <span class="typ DeliveryResponse<span class="pln
<span class="pun {<span class="pln
<span class="com // Public Properties<span class="pln
<span class="kwd public<span class="pln <span class="kwd string<span class="pln <span class="typ Message_Id<span class="pln
<span class="pun {<span class="pln
<span class="kwd get<span class="pln <span class="pun {<span class="pln <span class="kwd return<span class="pln <span class="typ Message_Id<span class="pun ;<span class="pln <span class="pun }<span class="pln
<span class="kwd set<span class="pln <span class="pun {<span class="pln <span class="typ Message_Id<span class="pln <span class="pun =<span class="pln value<span class="pun ;<span class="pln <span class="pun }<span class="pln
<span class="pun }<span class="pln
<span class="kwd public<span class="pln <span class="kwd string<span class="pln <span class="typ Message_Key<span class="pln
<span class="pun {<span class="pln
<span class="kwd get<span class="pln <span class="pun {<span class="pln <span class="kwd return<span class="pln <span class="typ Message_Key<span class="pun ;<span class="pln <span class="pun }<span class="pln
<span class="kwd set<span class="pln <span class="pun {<span class="pln <span class="typ Message_Key<span class="pln <span class="pun =<span class="pln value<span class="pun ;<span class="pln <span class="pun }<span class="pln
<span class="pun }<span class="pln
<span class="kwd public<span class="pln <span class="kwd string<span class="pln <span class="typ Status_Time<span class="pln
<span class="pun {<span class="pln
<span class="kwd get<span class="pln <span class="pun {<span class="pln <span class="kwd return<span class="pln <span class="typ Status_Time<span class="pun ;<span class="pln <span class="pun }<span class="pln
<span class="kwd set<span class="pln <span class="pun {<span class="pln <span class="typ Status_Time<span class="pln <span class="pun =<span class="pln value<span class="pun ;<span class="pln <span class="pun }<span class="pln
<span class="pun }<span class="pln
<span class="kwd public<span class="pln <span class="kwd string<span class="pln <span class="typ Device_Value<span class="pln
<span class="pun {<span class="pln
<span class="kwd get<span class="pln <span class="pun {<span class="pln <span class="kwd return<span class="pln <span class="typ Device_Value<span class="pun ;<span class="pln <span class="pun }<span class="pln
<span class="kwd set<span class="pln <span class="pun {<span class="pln <span class="typ Device_Value<span class="pln <span class="pun =<span class="pln value<span class="pun ;<span class="pln <span class="pun }<span class="pln
<span class="pun }<span class="pln
<span class="kwd public<span class="pln <span class="kwd string<span class="pln <span class="typ Device_Type<span class="pln
<span class="pun {<span class="pln
<span class="kwd get<span class="pln <span class="pun {<span class="pln <span class="kwd return<span class="pln <span class="typ Device_Type<span class="pun ;<span class="pln <span class="pun }<span class="pln
<span class="kwd set<span class="pln <span class="pun {<span class="pln <span class="typ Device_Type<span class="pln <span class="pun =<span class="pln value<span class="pun ;<span class="pln <span class="pun }<span class="pln
<span class="pun }<span class="pln
<span class="kwd public<span class="pln <span class="kwd string<span class="pln <span class="typ Message_Status<span class="pln
<span class="pun {<span class="pln
<span class="kwd get<span class="pln <span class="pun {<span class="pln <span class="kwd return<span class="pln <span class="typ Message_Status<span class="pun ;<span class="pln <span class="pun }<span class="pln
<span class="kwd set<span class="pln <span class="pun {<span class="pln <span class="typ Message_Status<span class="pln <span class="pun =<span class="pln value<span class="pun ;<span class="pln <span class="pun }<span class="pln
<span class="pun }<span class="pln
<span class="kwd public<span class="pln <span class="kwd string<span class="pln <span class="typ Message_Status_Description<span class="pln
<span class="pun {<span class="pln
<span class="kwd get<span class="pln <span class="pun {<span class="pln <span class="kwd return<span class="pln <span class="typ Message_Status_Description<span class="pun ;<span class="pln <span class="pun }<span class="pln
<span class="kwd set<span class="pln <span class="pun {<span class="pln <span class="typ Message_Status_Description<span class="pln <span class="pun =<span class="pln value<span class="pun ;<span class="pln <span class="pun }<span class="pln
<span class="pun }<span class="pln
<span class="com // Constructor<span class="pln
<span class="kwd public<span class="pln <span class="typ DeliveryResponse<span class="pun ()<span class="pln
<span class="pun {<span class="pln
<span class="pun }<span class="pln

<span class="pun }[/code]
Here is my Deserialize Code:
<pre class="prettyprint prettyprinted <span class="pln <span class="kwd private<span class="pln <span class="kwd void<span class="pln <span class="typ Deserialize<span class="pun (<span class="typ XDocument<span class="pln abc<span class="pun )<span class="pln
<span class="pun {<span class="pln

<span class="typ DeliveryResponse<span class="pln collectiondeliveryresponse <span class="pun =<span class="pln <span class="kwd new<span class="pln <span class="typ DeliveryResponse<span class="pun ();<span class="pln
<span class="typ XmlSerializer<span class="pln serializer <span class="pun =<span class="pln <span class="kwd new<span class="pln <span class="typ XmlSerializer<span class="pun (<span class="pln collectiondeliveryresponse<span class="pun .<span class="typ GetType<span class="pun ());<span class="pln
<span class="typ System<span class="pun .<span class="pln IO<span class="pun .<span class="typ StringReader<span class="pln sr <span class="pun =<span class="pln <span class="kwd new<span class="pln <span class="typ System<span class="pun .<span class="pln IO<span class="pun .<span class="typ StringReader<span class="pun (<span class="pln xDocDeliveryResponse<span class="pun .<span class="typ ToString<span class="pun ());<span class="pln
collectiondeliveryresponse <span class="pun =<span class="pln <span class="pun (<span class="typ DeliveryResponse<span class="pun )<span class="pln serializer<span class="pun .<span class="typ Deserialize<span class="pun (<span class="pln sr<span class="pun );<span class="pln
sr<span class="pun .<span class="typ Close<span class="pun ();<span class="pln
<span class="pun } [/code]




This is the error message received:
{System.InvalidOperationException: There is an error in XML document (1, 2). ---> System.InvalidOperationException: <TELEMESSAGE xmlns=> was not expected.<br/>
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderDeliveryResponse.Read3_DeliveryResponse()<br/>
--- End of inner exception stack trace ---<br/>
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, Object events)<br/>
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)<br/>
at System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader)<br/>
at Messaging.MainPage.Deserialize(XDocument abc)<br/>
at Messaging.MainPage.delmediator_DelToExternalServiceCompleted(Object sender, PostToExternalServiceCompletedEventArgs e)<br/>
at Messaging.svcMediator.MediatorServiceClient.OnPostToExternalServiceCompleted(Object state)}

View the full article
 
Back
Top