2011-04-04 107 views

回答

0

只需加載URL並檢查它實際上是一個RSS源。下面的代碼

try { 
    var feedDoc = XDocument.Load(url); 
    return ValidateRss(feedDoc); // implementation left as an exercise for the reader. 
} 
catch(HttpException) { // perhaps others 
    return false; 
} 
+0

我沒有ValidateRss方法: - ?它不是一個有效的方法。 – 2012-04-14 11:31:35

0

用於檢查RSS網址:

using System.ServiceModel.Syndication; 

    public static bool IsValidFeedUrl(string url) 
    { 
     bool isValid = true; 
     try 
     { 
      XmlReader reader = XmlReader.Create(url); 
      Rss20FeedFormatter formatter = new Rss20FeedFormatter(); 
      formatter.ReadFrom(reader); 
      reader.Close(); 
     } 
     catch 
     { 
      isValid = false; 
     } 

     return isValid; 
    }