I'm trying to deserialize an XML document from the web into associated classes for a Windows Phone 7 environment. I've used an async to grab the document, it loads into an XmlReader as far as I can tell with the debugger, and a deserializer reports it can be deserialized. When I try to deserialize I get an empty class.
This is the class I want to populate from the Xml:
namespace CineQuest
{
//[Serializable()]
//This is the main head of the XML data object
[XmlRoot("festival")]
public class Festival
{
/* Later */
//[XmlElement("program_items")]
//public ProgramItems programItems { get; set; }
[XmlElement("films")]
public Films films { get; set; }
[XmlElement("schedules")]
public Schedules schedules { get; set; }
/* Later */
//[XmlElement("venue_Locations")]
//public VenueLocations venueLocations { get; set; }
}
public class Films
{
[XmlArray("films")]
[XmlArrayItem("film", typeof(Film))]
public List<Film> filmsList { get; set; }
public Films()
{
filmsList = new List<Film>();
}
}
public class Film
{
[XmlElementAttribute("id")]
public string id { get; set; }
[XmlElement("title")]
public string title { get; set; }
[XmlElement("description")]
public string description { get; set; }
[XmlElement("tagline")]
public string tagline { get; set; }
[XmlElement("genre")]
public string genre { get; set; }
[XmlElement("imageURL")]
public string imageURL { get; set; }
[XmlElement("director")]
public string director { get; set; }
[XmlElement("producer")]
public string producer { get; set; }
[XmlElement("cinematographer")]
public string cinematographer { get; set; }
[XmlElement("editor")]
public string editor { get; set; }
[XmlElement("cast")]
public string cast { get; set; }
[XmlElement("country")]
public string country { get; set; }
[XmlElement("language")]
public string language { get; set; }
[XmlElement("film_info")]
public string film_info { get; set; }
}
public class Schedules
{
[XmlArray("schedules")]
[XmlArrayItem("schedule", typeof(Schedule))]
public List<Schedule> schedulesList { get; set; }
public Schedules()
{
schedulesList = new List<Schedule>();
}
}
public class Schedule
{
[XmlElementAttribute("id")]
public string id { get; set; }
[XmlElementAttribute("program_item_id")]
public string programItemId { get; set; }
[XmlElementAttribute("start_time")]
public string startTime { get; set; }
[XmlElementAttribute("end_time")]
public string endTime { get; set; }
[XmlElementAttribute("venue")]
public string venue { get; set; }
}
}
And this is how I'm trying to do it:
XmlSerializer serializer = new XmlSerializer(typeof(Festival));
reader = XmlReader.Create(new StringReader(data.Result));
object deserialization = serializer.Deserialize(reader);
MessageBox.Show(deserialization.ToString());
festival = (Festival)deserialization;
FilmItemList list = new FilmItemList(festival);
list.populateList();
foreach (FilmItem item in list.Itemlist)
{
this.Items.Add(new ItemViewModel() { LineOne = item.lineone, LineTwo = item.linetwo, LineThree = item.linethree, LineFour = item.linefour });
}
I know I can populate the classes as I've done it manually, but I know I'm missing something to connect the Xml being deserialized to the classes they're supposed to connect to, but I have no idea what.