I am trying to parse Rss2 Atom feeds using SyndicationFeedFormatter and SyndicationFeed objects. But I get XmlExceptions when parsing a DateTime field like pubDate and / or lastBuildDate.
Wed, Feb 24, 2010 6:56:04 PM GMT + 00: 00 not working
Wed, Feb 24, 2010 6:56:04 PM GMT
So, he rushed about from the time zone field.
As a workaround for familiar feeds, I manually fixed these DateTime nodes - catching an XmlException, loading Rss into an XmlDocument, setting the value of these nodes, creating a new XmlReader, and then returning the formatter from this new XmlReader object (code not shown). But for this approach to work, I need to know in advance which nodes throw an exception.
SyndicationFeedFormatter syndicationFeedFormatter = null; XmlReaderSettings settings = new XmlReaderSettings(); using (XmlReader reader = XmlReader.Create(url, settings)) { try { syndicationFeedFormatter = SyndicationFormatterFactory.CreateFeedFormatter(reader); syndicationFeedFormatter.ReadFrom(reader); } catch (XmlException xexp) { // fix those datetime nodes with exceptions and read again. } return syndicationFeedFormatter; }
rss channel: http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&q=test&cf=all&output=rss
exceptions:
XmlException Error at position 1 376. An error occurred while parsing the DateTime value in XML.
in System.ServiceModel.Syndication.Rss20FeedFormatter.DateFromString (String dateTimeString, XmlReader reader)
in System.ServiceModel.Syndication.Rss20FeedFormatter.ReadXml (XmlReader reader, result of SyndicationFeed) in System.ServiceModel.Syndication.Rss20FeedFormatter.ReadFrom (XmlReader reader) in ... cs: line 171
<rss version="2.0"> <channel> ... <pubDate>Wed, 24 Feb 2010 18:56:04 GMT+00:00</pubDate> <lastBuildDate>Wed, 24 Feb 2010 18:56:04 GMT+00:00</lastBuildDate> <-----exception ... <item> ... <pubDate>Wed, 24 Feb 2010 16:17:50 GMT+00:00</pubDate> <lastBuildDate>Wed, 24 Feb 2010 18:56:04 GMT+00:00</lastBuildDate> </item> ... </channel> </rss>
Is there a better way to achieve this? Please help. Thank you
datetime exception parsing rss
hIpPy
source share