Reputation: 31
I'm having trouble coming up with the correct code to download pictures from a RSS feed and then handing that download off to RadControls slide View or Pagination.
The only thing I can get with the code I'm using is either the text for the pictures or just thumbnails of the pictures, not the full image. I must be missing something or leaving something out.
This is for Windows Phone C#
The web links for the RSS feeds are generic for testing purposes.
//Constructor
public MainPage()
{
InitializeComponent();
}
private void FlickrSearch_Click(object sender, RoutedEventArgs e)
{
WebClient webclient = new WebClient();
webclient.DownloadStringCompleted += new DownloadStringCompletedEventHandler
(webclient_DownloadStringCompleted);
}
void webclient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show("error");
}
// parsing Flickr
XElement XmlTweet = XElement.Parse(e.Result);
XNamespace ns = "http://api.flickr.com/services/feeds/photos_public.gne?tag="; // flilckr
listBox1.ItemsSource =
from tweet in XmlTweet.Descendants("item")
select new FlickrData
{
ImageSource = tweet.Element(ns + "thumbnail").Attribute("url").Value,
Message = tweet.Element("description").Value,
UserName = tweet.Element("title").Value,
PubDate = DateTime.Parse(tweet.Element("pubDate").Value)
};
}
Upvotes: 2
Views: 475
Reputation: 7341
I have found the way you are parsing & fetching the inner data is erroneous. I have closely verified the XML data from Flickr and modified the logic accordingly.
Here goes the complete code:
void webclient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show("error");
}
// parsing Flickr
XElement XmlTweet = XElement.Parse(e.Result);
string ns = "http://www.w3.org/2005/Atom";
XName entry = XName.Get("entry", ns);
XName loc = XName.Get("loc", ns);
XName title = XName.Get("title", ns);
XName published = XName.Get("published", ns);
XName link = XName.Get("link", ns);
XName content = XName.Get("content", ns);
XName url = XName.Get("url", ns);
listBox1.ItemsSource =
from tweet in XmlTweet.Elements(entry)
select new FlickrData
{
ImageSource = tweet.Element(link).Attribute("href").Value,
Message = tweet.Element(content).Value,
UserName = tweet.Element(title).Value,
PubDate = DateTime.Parse(tweet.Element(published).Value)
};
}
Upvotes: 2