Exceptions with DateTime parsing in RSS feed in C#

后端 未结 2 1619
名媛妹妹
名媛妹妹 2021-02-04 19:13

I\'m trying to parse Rss2, Atom feeds using SyndicationFeedFormatter and SyndicationFeed objects. But I\'m getting XmlExceptions while parsing DateTime field like pubDate and/or

2条回答
  •  北荒
    北荒 (楼主)
    2021-02-04 19:44

    Here is my hacky workaround for reading Google News RSS feeds.

    string xml;
    using (WebClient webClient = new WebClient())
    {
        xml = Encoding.UTF8.GetString(webClient.DownloadData(url));
    }
    xml = xml.Replace("+00:00", "");
    byte[] bytes = System.Text.UTF8Encoding.ASCII.GetBytes(xml);  
    XmlReader reader = XmlReader.Create(new MemoryStream(bytes));
    SyndicationFeed feed = SyndicationFeed.Load(reader);
    

提交回复
热议问题