2009-05-12 8 views
2

をエンコード:LinqtoXML:私はそうのようなXMLへのLINQを使用して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 
        }; 

をしかし、私に何が一体このアイテムの要素を解析する方法:「文字の16進値0x3A、名前に含めることはできません 『』。」

私が手にエンコードされたアイテムこのエラー:コンテンツとの問題を持っています? RSSフィードを解析するはるかに簡単な方法はあり

答えて

8
XNamespace nsContent = "http://purl.org/rss/1.0/modules/content/"; 

// ... 

Content = item.Element(nsContent + "encoded").Value 

// ... 
1

SyndicationFeedクラス私は成功したコードの下にしてみてくださいRSSフィードを解析することができLinqtoxmlを使用してhere

+0

基本的には、別のクラスを除いて同じもの – dswatik

+0

実際のXMLスキーマについて心配する必要はありません。 –

0

こんにちは

詳細は

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; 

     }