SyndicationItem.Content为Null [英] SyndicationItem.Content is Null

查看:105
本文介绍了SyndicationItem.Content为Null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将RSS提要的内容拉入可以用代码操作的对象.看起来.NET 3.5中的SyndicationFeed和SyndicationItem类将满足我的需要,除了一件事.每当我尝试使用SyndicationFeed类读取RSS feed的内容时,每个SyndicationItem的.Content元素都为null.

I'm trying to pull the contents of an RSS feed into an object that can be manipulated in code. It looks like the SyndicationFeed and SyndicationItem classes in .NET 3.5 will do what I need, except for one thing. Every time I've tried to read in the contents of an RSS feed using the SyndicationFeed class, the .Content element for each SyndicationItem is null.

我已经通过FeedValidator运行了Feed,并尝试了其他几种来源的Feed,但无济于事.

I've run my feed through FeedValidator and have tried this with feeds from several other sources, but to no avail.

XmlReader xr = XmlReader.Create("http://shortordercode.com/feed/");
SyndicationFeed feed = SyndicationFeed.Load(xr);

foreach (SyndicationItem item in feed.Items)
{
    Console.WriteLine(item.Title.Text);
    Console.WriteLine(item.Content.ToString());
}

Console.ReadLine();

我怀疑我可能只是在某个地方缺少了一步,但是我似乎找不到关于如何使用这些类使用RSS提要的很好的教程.

I suspect I may just be missing a step somewhere, but I can't seem to find a good tutorial on how to consume RSS feeds using these classes.

感谢SLaks,我发现问题出在WordPress将用作内容标签. WP Atom提要似乎没有问题,所以我现在将其作为解决方案.谢谢SLaks!

Thanks to SLaks I've figured out that the issue is with WordPress's use of as the content tag. This doesn't appear to be a problem with the WP Atom feeds so I'll go with that as a solution for now. Thanks SLaks!

推荐答案

这应该为您获取内容:

SyndicationFeed feed = SyndicationFeed.Load(reader);

string content = feed.ElementExtensions.ReadElementExtensions<string>("encoded", "http://purl.org/rss/1.0/modules/content/")

这篇关于SyndicationItem.Content为Null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆