【问题标题】:SyndicationFeed RSS: Element 'channel' with namespace name '' was not foundSyndicationFeed RSS:未找到名称空间名称为“”的元素“频道”
【发布时间】:2014-02-18 14:26:34
【问题描述】:

我正在尝试将 rss(xml 格式)作为数据源加载,但是当我尝试将其加载到 Syndication 提要时,它会引发错误:

未找到命名空间名称为“”的元素“通道”。第 1 行,位置 21。

这是我的代码:

public IEnumerable<FeedItem> GetRssFeedList()
{
    XmlReader reader = XmlReader.Create(_urlRssFeed);
    SyndicationFeed feed = SyndicationFeed.Load(reader);
    var feedItems = feed.Items.Select(c=> new FeedItem { Title = c.Title.Text, Link = c.Links.FirstOrDefault().ToString(), Description = c.Summary.Text});
    return feedItems;
}

_urlRssFeed = "http://www.educaweb.com/rss/actualidad/"

我检查了它是否是一个有效的 RSS 并且它是: http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fwww.educaweb.com%2Frss%2Factualidad%2F

我不知道它可能是什么?提前致谢。

顺便说一下,这是我的自定义提要项目类:

public class FeedItem
{
    public string Title { get; set; }
    public string Link { get; set; }
    public string Description { get; set; }
}

希望能帮到我! 谢谢!

【问题讨论】:

  • 会不会是 w3.org/1999/xhtml" /> ?不知道为什么会这样!
  • 我该怎么做才能将其删除并使其正常工作?我无法修改 rss...

标签: c# xml rss syndication


【解决方案1】:

<meta name="robots" .../>

标签可能是原因。这是我为 huffingtonpost (https://www.huffingtonpost.com/dept/entertainment/feed) 解决的方法。

private static Stream RemoveInvalidRssText(Stream stream)
{
    var text = new StreamReader(stream).ReadToEnd(); // convert stream to string
    text = Regex.Replace(text, "<meta name=\"robots\" content=\"noindex\" xmlns=\"http://www.w3.org/1999/xhtml\" />", "");
    return new MemoryStream(Encoding.UTF8.GetBytes(text)); // convert to string to stream
}

但在 huffingtonpost 或问题中提到的提要上不再存在此问题。也许提要升级到更新的 RSS 规范。

显然,我使用的解决方法会增加将流转换为字符串、删除问题文本并将其转换回流的处理时间。因此,您需要将此步骤限制为有问题的提要。

【讨论】:

    猜你喜欢
    • 2013-04-01
    • 1970-01-01
    • 2021-05-17
    • 1970-01-01
    • 2020-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多