I have the following XML data list:
<xml>
<cnt>7469</cnt>
<emails>
<item>
<to_email>[email protected]</to_email>
<id>3352143303</id>
<app_id>121746</app_id>
<subject>[REF:GAR23004513_6470_0]</subject>
<status>blocked</status>
<sendtime_start>1406559567</sendtime_start>
<sendtime_end>1406559567</sendtime_end>
<from_id>2726590621</from_id>
<from_name/>
<from_email>[email protected]</from_email>
<email_id>9158240961</email_id>
<state_id>14</state_id>
<to_id>1220492939</to_id>
<cnt_recipients>1</cnt_recipients>
<sent/>
<open/>
<click/>
<bounce/>
<spam/>
<blocked>1</blocked>
<queued>0</queued>
<status_message>preblocked</status_message>
</item>
</emails>
<status>OK</status>
</xml>
And I wanted to Serialize it so it could be easier to read the data. For that, I created the following view model:
EmailViewModel.cs (edited)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MvcTesteLayout.ViewModels
{
[System.SerializableAttribute()]
public class EmailViewModel
{
public string cnt { get; set; }
public class emails {
public item[] item;
}
public class item {
public string to_email { get; set; }
public string id { get; set; }
public string app_id { get; set; }
public string subject { get; set; }
public string status { get; set; }
public string sendtime_start { get; set; }
public string sendtime_end { get; set; }
public string from_id { get; set; }
public string from_name { get; set; }
public string from_email { get; set; }
public string email_id { get; set; }
public string state_id { get; set; }
public string to_id { get; set; }
public string sent { get; set; }
public string open { get; set; }
public string click { get; set; }
public string bounce { get; set; }
public string spam { get; set; }
public string blocked { get; set; }
public string queued { get; set; }
public string status_message { get; set; }
}
}
}
Now the questions: How do I serialize this list of data (since more than one result can come in XML)? Do I also need to add a field in my class to the parent nodes (eg emails)?