我是 下面這個教程:http://www.developer.nokia.com/Community/Wiki/Employees_app_with_XML_parsing_and_messaging_in_WP7解析圖像中的WP7應用程序的XML
我有這樣的應用程序,顯示在我的城市的事件,每個事件都得到了一個形象,一個標題,如果我點擊一個事件我我會進入細節頁面,向我展示更大的圖像,標題和事件描述,所有與教程類似的內容,實際上它工作得很好,問題是什麼?它只顯示我一個事件。
在這裏你可以看到,我使用的飼料:
http://th05.deviantart.net/fs70/PRE/f/2012/226/0/7/xml_by_javabak-d5b1d16.png
這是我的活動類:
namespace Bluey
{
[XmlRoot("rss")]
public class Eventi
{
[XmlArray("channel")]
[XmlArrayItem("item")]
public ObservableCollection<Evento> Collect { get; set; }
}
}
,這是我的事件類
namespace Bluey
{
public class Evento
{
[XmlElement("title")]
public string title { get; set; }
[XmlElement("enclosure")]
public string image { get; set; }
[XmlElement("description")]
public string description { get; set; }
}
}
我注意到在事件類中,如果我將[XmlElement(「enclosure」)]更改爲[Xm lElement( 「URL」)]我會得到所有的事件,但沒有圖像
這是我的解析器
public EventiPage()
{
InitializeComponent();
// is there network connection available
if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
{
MessageBox.Show("No network connection available!");
return;
}
// start loading XML-data
WebClient downloader = new WebClient();
Uri uri = new Uri("http://www.applinesrl.com/appoggio/events/feed", UriKind.Absolute);
downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(EventiDownloaded);
downloader.DownloadStringAsync(uri);
}
void EventiDownloaded(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Result == null || e.Error != null)
{
MessageBox.Show("There was an error downloading the XML-file!");
}
else
{
XmlSerializer serializer = new XmlSerializer(typeof(Eventi));
XDocument document = XDocument.Parse(e.Result);
Eventi eventi = (Eventi)serializer.Deserialize(document.CreateReader());
EventiList.ItemsSource = eventi.Collect;
}
}
任何幫助將apreciated,TNX在諮詢!
迭戈。
謝謝,我已經嘗試過你的建議,但它在解析xml在這一行時拋出異常XDocument document = XDocument.Parse(e.Result);我現在正在尋找這種機箱嵌套的解決方案:/ – 2012-08-13 14:02:26
確定我的錯,嘗試更改Feed以尋求更快的解決方案,並且忘記返回舊的Feed以獲取例外情況...我很抱歉(大概5個小時,我開始製作非常愚蠢的錯誤),無論如何,您的建議會將整個訂閱源返回給我,除了圖像 – 2012-08-13 14:44:28
我不確定您是如何實現代碼的。但是,你明白現在圖像的URL會像這個image.url一樣可用。我已經更新了上面的代碼以包含如何訪問url的部分。 – 2012-08-13 16:59:11