0

我有以下 rss 提要,它包含有关其他 rss 提要的信息,最终它会有数据。当用户选择任何 rss 提要(我想按他们的名字显示根 rss 提要的子 rss 提要)时,将显示有关所选 rss 提要的信息。

http://www.espncricinfo.com/ci/content/rss/feeds_rss_cricket.html

 public static void Read(string url)
    {
        WebClient webClient = new WebClient();
        webClient.DownloadStringCompleted += webClient_DownloadStringCompleted;
        webClient.DownloadStringAsync(new Uri( url));            
    }

 static void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        XDocument document = XDocument.Parse(e.Result);

        //return (from descendant in document.Descendants("item")
        //        select new RssNews()
        //        {
        //            Description = descendant.Element("description").Value,
        //            Title = descendant.Element("title").Value,
        //            PublicationDate = descendant.Element("pubDate").Value
        //        }).ToList();
    }

我尝试了下面的代码,但它显示了一个异常。知道如何解决这个问题吗?

System.ni.dll 中出现“System.Reflection.TargetInvocationException”类型的异常,但未在用户代码中处理

4

1 回答 1

0

您的代码(包括 xml 解析)工作正常,但您的 url 指向一个 html 页面,其中包含 rss feed 的 url,而不是 rss feed。

试试,例如,这个网址。http://www.espncricinfo.com/rss/content/story/feeds/1.xml取自该页面。

于 2013-03-03T18:06:26.363 回答