2

I'm using SyndicationFeed to retrive some data from diffrent RSS-sources. However, I just ran in to a problem when trying to read a RSS that as far as I can see has the same elements and data as ones that do work.

SyndicationFeed feed = SyndicationFeed.Load(XmlReader.Create("http://rsslink"));

For example, this RSS works just fine and is accepted without errors: http://kjellochklortanten.libsyn.com/rss

While this RSS: http://feeds.feedburner.com/tedtalks_audio causes the SyndicationFeed to throw an error (this is translated from Swedish):

An error occurred when parsing a DateTime-value in XML

I've looked at the dates in both feeds and as far as i can see they are identical.

Any C#-ninja out there that has a clue what might cause this error?

Thanks in advance!

Subtractive
  • 500
  • 2
  • 9
  • 19
  • Could you provide the offending XML? – Richard Schneider May 02 '14 at 00:32
  • Hi! I posted the links to a working RSS/XML-feed, and a non-working one. Will that suffice? :) – Subtractive May 02 '14 at 00:35
  • Ah you mean which line perhaps where the error occurred? For the TedTalk-RSS it's: Thu, 01 May 2014 10:00:13 UTC. Perhaps it's the "UTC" that's causing the problem? – Subtractive May 02 '14 at 01:06
  • That date is not a valid XML date-time. You will need to treat it as string and parse it yourself. – Richard Schneider May 02 '14 at 01:08
  • Thank you, this answer sent me in the right direction of finding how to solve it all, http://stackoverflow.com/a/3936714/3257261 - should i perhaps add this link as answer to my question as well, or is this comment enough? (StackOverflow newbie). – Subtractive May 02 '14 at 01:20
  • possible duplicate of [Exceptions with DateTime parsing in RSS feed in C#](http://stackoverflow.com/questions/2328770/exceptions-with-datetime-parsing-in-rss-feed-in-c-sharp) – har07 May 02 '14 at 02:12
  • Hopefully you've now dealt with the problem, but as a note, if you have a future question about such an issue, including the XML in your question would be **far** more useful than just including the links. Your question becomes a lot less clear if and when they clean up their act and start producing proper RSS without the issue you're having. Or if the links become invalid. (Or even, I suppose it could happen, if the "good" RSS feed becomes broken) – Damien_The_Unbeliever May 02 '14 at 08:40

1 Answers1

5

This problem occurs because of the date format that is used in the second feed. The SyndicationFeed.Load method expects to receive feeds that are in standard format. The following is an example of standard format:

Mon, 05 Oct 2009 08:00:06 GMT

However, the lastBuildDate in the feed is:

Fri, 02 May 2014 04:58:16 UTC

To work around this problem, create a custom XML reader that recognizes that format. Copy entire code of MyXmlReader and replace

const string CustomUtcDateTimeFormat = "ddd MMM dd HH:mm:ss Z yyyy";  

by

const string CustomUtcDateTimeFormat = "ddd, dd MMM yyyy HH:mm:ss 'UTC'";

Now use it as

//var feed = SyndicationFeed.Load(XmlReader.Create("http://feeds.feedburner.com/tedtalks_audio"));
XmlReader r = new MyXmlReader("http://feeds.feedburner.com/tedtalks_audio"); 
var feed = SyndicationFeed.Load(r);

That code will work for both feeds.

Hej da

user2316116
  • 6,726
  • 1
  • 21
  • 35