SyndicationFeed RSS:找不到名称空间名称为''的元素'通道'

时间:2014-01-27 16:27:35

标签: c# xml rss syndication

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

找不到名称空间名称为''的元素'频道'。第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

我不知道它会是什么?提前谢谢。

顺便说一下,这是我的自定义Feed项:

public class FeedItem
{
    public string Title { get; set; }
    public string Link { get; set; }
    public string Description { get; set; }
}
希望可以帮助我! 谢谢!

1 个答案:

答案 0 :(得分:0)

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

标签是原因。这是我解决的方法:

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
}

我注意到,YouKU优酷RSS提要也存在同样的问题,例如:https://www.huffingtonpost.com/dept/entertainment/feed

显然,这将增加处理时间,以将流转换为字符串,去除问题文本并将其转换回流。因此,您需要将此步骤限制为有问题的供稿。