Reputation: 1427
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!
Upvotes: 1
Views: 1035
Reputation: 31
The
<meta name="robots" .../>
tag was likely the cause. Here's how I solved it for 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
}
But it is no longer having this problem on huffingtonpost or the feed mentioned in the question. Perhaps the feeds upgraded to a newer RSS spec.
Obviously the work-around I was using 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.
Upvotes: 0