RSS源问题 [英] Problem with RSS Feeds
本文介绍了RSS源问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我正在尝试使用Windows Phone App Studio为我的techblog创建一个应用程序。实际上它是一个RSS阅读器。我试图创建那个阅读器,但在手机上它没有显示整篇文章 - 只是前4-5行,然后是"[...]"。显示微软新闻的
默认RSS源似乎工作正常(你可以阅读整篇文章)。你知道我能解决这个问题吗?
帖子是希腊文...
I'm trying to create an app for my techblog, using Windows Phone App Studio of course. Actually it's an RSS reader. I tried to create that reader but on the phone it doesn't show the whole article - just the first 4-5 lines and then "[...]". The default RSS feed that shows Microsofts news seems to work fine (you can read the whole post). Do you know if I can fix this problem? Posts are in Greek...
推荐答案
我想你必须手动编辑正在显示的文本格式
I guess you have to manually edit the format of text being displayed
希望这段代码能帮助..
Hope this code helps..
class Class1
{
public ObservableCollection<RSSItem> FeedItems = new ObservableCollection<RSSItem>();
void method1()
{
WebClient wc = new WebClient();
wc.DownloadStringCompleted += wc_DownloadStringCompleted;
wc.DownloadStringAsync(new Uri(_feedUrl), UriKind.Absolute);
}
private void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try
{
XmlReader reader = XmlReader.Create(GenerateStreamFromString(e.Result));
SyndicationFeed rssFeed = SyndicationFeed.Load(reader);
var items = from p in rssFeed.Items
select new RSSItem
{
Title = p.Title.Text,
Summary = FormatSummary(p).Trim(),
Permalink = (p.Links.FirstOrDefault() != null) ? p.Links.FirstOrDefault().GetAbsoluteUri() : null,
PublishDate = p.PublishDate.LocalDateTime.ToString(),
ImageUrl = UpdateFeedImageUrl(p)
};
FeedItems = items.ToList();
}
catch (Exception ex)
{
}
}
public Stream GenerateStreamFromString(string s)
{
MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(stream);
writer.Write(s);
writer.Flush();
stream.Position = 0;
return stream;
}
/// <summary>
/// Trim the html tags
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
private string FormatSummary(SyndicationItem p)
{
const string HTML_TAG_PATTERN = "<.*?>";
if (!String.IsNullOrEmpty(p.Summary.Text))
return Regex.Replace(p.Summary.Text, HTML_TAG_PATTERN, string.Empty);
else
return string.Empty;
}
private Uri UpdateFeedImageUrl(SyndicationItem p)
{
if (p.Links != null)
{
foreach (SyndicationLink enclosure in p.Links.Where<SyndicationLink>(x => x.RelationshipType == "enclosure"))
{
if (enclosure.MediaType == "image/jpeg")
{
return enclosure.Uri; ;
}
}
}
return null;
}
}
public class RSSItem
{
public System.Uri ImageUrl { get; set; }
public System.Uri Permalink { get; set; }
public string PublishDate { get; set; }
public string Summary { get; set; }
public string Title { get; set; }
}
这篇关于RSS源问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文