简体   繁体   中英

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:

Element 'channel' with namespace name '' was not found. Line 1, position 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/ "

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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