0

I'm trying to figure out why this site's RSS feed suddenly broke, and how I might go about fixing it.

This is the error information my company gave me to help fix it:

Error in line 17 position 39. An error was encountered when parsing a DateTime value in the XML.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Xml.XmlException: Error in line 17 position 39. An error was encountered when parsing a DateTime value in the XML.

Source Error:

Line 25: settings.DtdProcessing = DtdProcessing.Parse;

Line 26: XmlReader reader = XmlReader.Create(url, settings);

Line 27: SyndicationFeed feed = SyndicationFeed.Load(reader);

Line 28:

Line 29: foreach (SyndicationItem item in feed.Items.Take(NUMBEROFPOSTS)) {

Source File: ***\prosenstein-com\Models\NewsFeedModel.cs Line: 27

Stack Trace:

[XmlException: Error in line 17 position 39. An error was encountered when parsing a DateTime value in the XML.] System.ServiceModel.Syndication.Atom10FeedFormatter.DateFromString(String dateTimeString, XmlReader reader) +4372522

Below is what I believe to be the pertinent model code within the site's MVC framework.

private List<SyndicationItem> GetItemsFromUrl(string url) {
    int NUMBEROFPOSTS = 6; // limits number of rss posts on page

    List<SyndicationItem> postsList = new List<SyndicationItem>();
    XmlReaderSettings settings = new XmlReaderSettings();
    settings.DtdProcessing = DtdProcessing.Parse;
    XmlReader reader = XmlReader.Create(url, settings);
    SyndicationFeed feed = SyndicationFeed.Load(reader);

    foreach (SyndicationItem item in feed.Items.Take(NUMBEROFPOSTS)) {
        item.Id = item.Links[0].Uri.ToString();
        postsList.Add(item);
    }

    reader.Close();
    return postsList;
}

I'm pretty new to coding in MVC, and most of this code looks like Greek to me. If you could help me solve the problem, and also help me learn something in the process, I'd be most appreciative.

  • You error is caused because your code couldn't parse a DateTime value. Can you share the rss source? – Mauricio Arias Olave Mar 02 '17 at 17:01
  • I think this was the source: http://www.huffingtonpost.com/author/peter-174 – Juddson Ivines Mar 02 '17 at 18:38
  • I don't think that this source is a XML valid source. Check how to use [SyndicationFeed](https://msdn.microsoft.com/en-us/library/system.servicemodel.syndication.syndicationfeed(v=vs.110).aspx). – Mauricio Arias Olave Mar 02 '17 at 18:54
  • Thanks for the literature, but a lot of it doesn't make much sense to me just yet. Is this the XML you were looking for? http://www.huffingtonpost.com/author/peter-174/feed – Juddson Ivines Mar 02 '17 at 19:20
  • Judson, exactly, you didn't provide the correct URL though _(hence, my previous comment)_. I'm testing the URL source in a console application and it seems that the DateTime is detected as an invalid one. You can search: [Problems Reading RSS with C# and .net 3.5](http://stackoverflow.com/q/210375/4092887) or look in Google using the keyworkds: `An error was encountered when parsing a DateTime value in the XML.`. Sorry that I can't give you more help. Good luck. – Mauricio Arias Olave Mar 02 '17 at 19:52

0 Answers0