SyndicateItem.Content 为空
我正在尝试将 RSS 提要的内容提取到可以在代码中操作的对象中。看起来 .NET 3.5 中的 SyndicateFeed 和 SyndicateItem 类将满足我的需要,除了一件事之外。每次我尝试使用 SyndicateFeed 类读取 RSS 提要的内容时,每个 SyndicateItem 的 .Content 元素都为 null。
我已通过 FeedValidator 运行我的提要,并尝试使用其他几个来源的提要进行此操作,但无济于事。
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 提要的好教程。
编辑:感谢 SLAks,我发现问题出在 WordPress 使用内容标签。这似乎不是 WP Atom 提要的问题,因此我现在将其作为解决方案。谢谢斯拉克斯!
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.
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();
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.
EDIT: 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这应该为您提供内容:
This should get content for you:
这是因为它是内容:编码而不是内容。要阅读本例中的内容,我将使用以下内容:
Its due to the fact that it is content:encoded instead of content. To read the content in this case, I am going to use this:
看看我做了什么:
Take a look what I did:
使用
Summary
属性。您链接到的 RSS 提要将其内容放入
元素中。如文档所述 ,RSS 提要的
元素映射到Summary
属性。Use the
Summary
property.The RSS feed you linked to puts its content in the
<description>
element.As documented, the
<description>
element of an RSS feed maps to theSummary
property.