Reading non-standard elements in a SyndicationItem with SyndicationFeed

前端 未结 5 643
挽巷
挽巷 2020-12-02 09:08

With .net 3.5, there is a SyndicationFeed that will load in a RSS feed and allow you to run LINQ on it.

Here is an example of the RSS that I am loading:

<         


        
5条回答
  •  伪装坚强ぢ
    2020-12-02 09:30

    Whether you're retrieving the non-XML contents of extension elements or XElement items, you might want to consider using a generic helper function like:

    private static T GetExtensionElementValue(SyndicationItem item, string extensionElementName)
    {
           return item.ElementExtensions.First(ee => ee.OuterName == extensionElementName).GetObject();
    }
    

    Depending on whether the elements are guaranteed to be there or whether you are putting this into a reusable library, you may need to add additional defensive programming.

提交回复
热议问题