Building a Simple RSS reader, retrieving content

痴心易碎 提交于 2019-12-01 05:02:55

问题


I am trying to make a simple RSS reader using SyndicationFeed class.

There are some standard tags, like <title>, <link>, <description>... there is no problem with them.

But there are some other tags. for example, in this feed, which created by WordPress, there is <content:encoded> tag. I think there may be other tags for the content part of other websites. right?

I want to know, how to find the main content of every post, is there any standards? which tags should I look for?

(for example, a site may use <content:encoded> but some other just use <description> or someone use another standard... I don't know what to do for retrieving the main content of a post)

P.S : I'm using this code for testing my simple RSS reader:

        var reader = XmlReader.Create("http://feed.2barnamenevis.com/2barnamenevis");
        var feed = SyndicationFeed.Load(reader);

        string s = "";
        foreach (SyndicationItem i in feed.Items)
        {
            s += i.Title.Text + "<br />" + i.Summary.Text + "<br />" + i.PublishDate.ToString() + "<br />";
            foreach (SyndicationElementExtension extension in i.ElementExtensions)
            {
                XElement ele = extension.GetObject<XElement>();
                s += ele.Name + " :: " + ele.Value + "<br />";
            }
            s += "<hr />";
        }
        return s;

回答1:


From our discussion in the comments, I'd probably suggest going with a 3rd party vendor instead of building it from scratch - Argotic and RSS.NET both look promising.




回答2:


Depends on what you want to support. Content element isn't part of RSS2.0 but is is of Atom (rss 4287).

Read RSS2.0 specs http://cyber.law.harvard.edu/rss/rss.html#hrelementsOfLtitemgt Read Atom specs http://tools.ietf.org/html/rfc4287




回答3:


I have found Argotic Syndication Framework (thanks from JoeEnos).

Argotic has many Extensions, which can be used for handling elements which are not standard.

For example, You can use Argotic.Extensions.Core.SiteSummaryContentSyndicationExtension for retrieving <content:encoded>. You can see an example here. (if that example returns null for content, you should simply use MyRssItem.Description)

Some other useful extensions are WellFormedWebCommentsSyndicationExtension (for retrieving comments feed url) and SiteSummarySlashSyndicationExtension (for retrieving comments count).



来源:https://stackoverflow.com/questions/11016213/building-a-simple-rss-reader-retrieving-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!