【问题标题】:LinqtoXML parsing RSS content:encodedLinqtoXML 解析 RSS 内容:编码
【发布时间】:2016-03-01 00:47:05
【问题描述】:

我正在尝试使用 Linq to XML 解析 RSS 提要,如下所示:

        XNamespace slashNamespace = "http://purl.org/rss/1.0/modules/slash/"; 
        XDocument rssFeed = XDocument.Load(@"http://blog.daimokuchart.com/index.php/feed/");

        var posts = from item in rssFeed.Descendants("item")
                    select new RSSData {
                        Title = item.Element("title").Value,
                        Published = DateTime.Parse(item.Element("pubDate").Value),
                        Url = item.Element("link").Value,
                        Content = item.Element("content:encoded").Value
                    };

但是;内容有问题:编码项目我收到此错误 “':' 字符,十六进制值 0x3A,不能包含在名称中。”

我到底是如何解析这个 item 元素的?

【问题讨论】:

    标签: asp.net-mvc linq-to-xml


    【解决方案1】:
    XNamespace nsContent = "http://purl.org/rss/1.0/modules/content/";
    
    // ...
    
    Content = item.Element(nsContent + "encoded").Value
    
    // ...
    

    【讨论】:

      【解决方案2】:

      有一种更简单的方法来解析 RSS 提要:SyndicationFeed

      更多详情here

      【讨论】:

      • 除了不同的类之外基本相同
      【解决方案3】:

      您好,我使用 Linqtoxml 并成功解析 Rss 提要,尝试下面的代码

      public apheadlines()
              {
                  InitializeComponent();
                  InitializeComponent();
                  WebClient downloader = new WebClient();
                  Uri rssurl = new Uri("http://ibnlive.in.com/ibnrss/rss/southcinema/telugunews.xml", UriKind.Absolute);
                  downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(downloads);
                  downloader.DownloadStringAsync(rssurl);
              }
      
      
       private void downloads(object sender, DownloadStringCompletedEventArgs e)
              {
                  if (e.Result == null)
                  {
                      MessageBox.Show("Error in download");
                  }
                  var Rss = from rss in XElement.Parse(e.Result).Descendants("item")
                            select new Data
                            {
                                Titles = rss.Element("title").Value.ToUpper(),
                                pubDate = rss.Element("pubDate").Value.Substring(0, 17)
      
                            };
      
                  listBox1.ItemsSource = Rss;
      
              }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-12-09
        • 1970-01-01
        • 2013-11-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多