我正在使用xamarin c#创建一个需要在visual studio中支持多语言新闻的新闻应用。我正在使用下面的代码。
List<FeedItem> feedItemsList = new List<FeedItem>();
try
{
HttpClient wc = new HttpClient();
var html = wc.GetStringAsync(new Uri(url)).Result;
XElement xmlitems = XElement.Parse(html);
// We need to create a list of the elements
List<XElement> elements = xmlitems.Descendants("item").ToList();
// Now we're putting the informations that we got in our ListBox in the XAML code
// we have to use a foreach statment to be able to read all the elements
// Description , Link , Title are the attributes in the RSSItem class that I've already added
List<FeedItem> aux = new List<FeedItem>();
foreach (XElement rssItem in elements)
{
FeedItem rss = new FeedItem();
rss.Description = rssItem.Element("description").Value;
rss.Link = rssItem.Element("link").Value;
rss.Title = rssItem.Element("title").Value;
feedItemsList.Add(rss);
}
}
catch (Exception)
{
throw;
}
此代码不适用于https://news.google.com/news/feeds?pz=1&cf=all&ned=zh-Hans&hl=china&q=topstories&output=rss
但适用于http://news.google.com/?output=rss
其他信息: 上面的代码适用于Windows Phone应用程序中的任何Feedur。