SyndicateItem.Content 为空

发布于 2024-08-25 07:02:02 字数 687 浏览 6 评论 0原文

我正在尝试将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

浅语花开 2024-09-01 07:02:02

这应该为您提供内容:

SyndicationFeed feed = SyndicationFeed.Load(reader);

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

This should get content for you:

SyndicationFeed feed = SyndicationFeed.Load(reader);

string content = feed.ElementExtensions.ReadElementExtensions<string>("encoded", "http://purl.org/rss/1.0/modules/content/")
佞臣 2024-09-01 07:02:02

这是因为它是内容:编码而不是内容。要阅读本例中的内容,我将使用以下内容:

    string content="";
    foreach (SyndicationElementExtension ext in item.ElementExtensions)
    {
        if (ext.GetObject<XElement>().Name.LocalName == "encoded")
            content = ext.GetObject<XElement>().Value;
    }

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:

    string content="";
    foreach (SyndicationElementExtension ext in item.ElementExtensions)
    {
        if (ext.GetObject<XElement>().Name.LocalName == "encoded")
            content = ext.GetObject<XElement>().Value;
    }
空袭的梦i 2024-09-01 07:02:02

看看我做了什么:

    XmlReader reader = XmlReader.Create("http://kwead.com/blog/?feed=atom");
    SyndicationFeed feed = SyndicationFeed.Load(reader);
    reader.Close();

    foreach (SyndicationItem item in feed.Items)
    {
        string data = item.PublishDate.ToString();
        DateTime dt = Convert.ToDateTime(data);

        string titulo = " - " + item.Title.Text + "<br>";
        string conteudo = ((TextSyndicationContent)item.Content).Text;

        Response.Write(dt.ToString("d"));
        Response.Write(titulo);
        Response.Write(conteudo);
     }

Take a look what I did:

    XmlReader reader = XmlReader.Create("http://kwead.com/blog/?feed=atom");
    SyndicationFeed feed = SyndicationFeed.Load(reader);
    reader.Close();

    foreach (SyndicationItem item in feed.Items)
    {
        string data = item.PublishDate.ToString();
        DateTime dt = Convert.ToDateTime(data);

        string titulo = " - " + item.Title.Text + "<br>";
        string conteudo = ((TextSyndicationContent)item.Content).Text;

        Response.Write(dt.ToString("d"));
        Response.Write(titulo);
        Response.Write(conteudo);
     }
你曾走过我的故事 2024-09-01 07:02:02

使用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 the Summary property.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文