2013-05-07 81 views
0

我試圖從Web反序列化XML文檔到Windows Phone 7環境的關聯類。我已經使用異步來獲取文檔,只要調試器能夠告訴它就加載到XmlReader中,並且反序列化器報告它可以反序列化。當我嘗試反序列化時,我得到一個空的類。反序列化XML無法將類連接到元素

這是我想從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; } 
} 
} 

這是我正在努力做到這一點:

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 }); 
} 

我知道我可以填充類作爲我已經手動完成了它,但是我知道我錯過了將被反序列化的Xml連接到它們應該連接的類的東西,但是我不知道是什麼。

回答

0

我相信你必須用Serializable屬性修飾你的所有類,如果它們要被序列化的話。