简体   繁体   English

SyndicationFeed RSS:找不到名称空间名为“”的元素“ channel”

[英]SyndicationFeed RSS: Element 'channel' with namespace name '' was not found

I am trying to load as a datasource an rss (xml format), but when I am trying to load it to the Syndication feed it raise an error: 我正在尝试将rss(xml格式)加载为数据源,但是当我尝试将其加载到联合供稿时,会引发错误:

Element 'channel' with namespace name '' was not found. 找不到名称空间名为“”的元素“通道”。 Line 1, position 21. 第1行,位置21。

This is my Code: 这是我的代码:

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;
}

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

I checked if it was a valid RSS and it it: http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fwww.educaweb.com%2Frss%2Factualidad%2F 我检查了它是否是有效的RSS,它是否是: http : //validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fwww.educaweb.com%2Frss%2Factualidad%2F

I dont know what it could be? 我不知道那会是什么? Thanks in advance. 提前致谢。

By the way this is my custom feed item class: 顺便说一下,这是我的自定义提要项类:

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

Hope can help me! 希望可以帮到我! Thanks! 谢谢!

The

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

tag is the cause. 标签是原因。 Here's how I solved it: 这是我解决的方法:

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
}

I noticed this same problem with huffingtonpost RSS feeds, example: https://www.huffingtonpost.com/dept/entertainment/feed 我注意到了huffingtonpost RSS feed的相同问题,例如: https : //www.huffingtonpost.com/dept/entertainment/feed

Obviously this will increase processing time to convert the stream to a string, strip out the problem text, and convert it back to a stream. 显然,这将增加将流转换为字符串,去除问题文本并将其转换回流的处理时间。 So you'll want to limit this step to feeds that have the problem. 因此,您需要将此步骤限制为有问题的供稿。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM