C# 在ASP.NET MVC 5应用程序的RSS提要中解析媒体文件并获取全文描述

C# 在ASP.NET MVC 5应用程序的RSS提要中解析媒体文件并获取全文描述,c#,asp.net-mvc-5,rss-reader,C#,Asp.net Mvc 5,Rss Reader,我需要解析RSS提要媒体文件(视频和图像),然后按如下方式显示它们: 我用来显示除媒体以外的信息的代码(我在网上搜索了一下,但没有找到任何有用的东西) string RssFeedUrl=“RssFeedUrl HERE”; 列表提要=新列表(); 尝试 { XDocument xDoc=新的XDocument(); xDoc=XDocument.Load(RssFeedUrl); var items=(从xDoc.subjects(“item”)中的x开始) 选择新的 { title=x.元

我需要解析RSS提要媒体文件(视频和图像),然后按如下方式显示它们:

我用来显示除媒体以外的信息的代码(我在网上搜索了一下,但没有找到任何有用的东西)

string RssFeedUrl=“RssFeedUrl HERE”;
列表提要=新列表();
尝试
{
XDocument xDoc=新的XDocument();
xDoc=XDocument.Load(RssFeedUrl);
var items=(从xDoc.subjects(“item”)中的x开始)
选择新的
{
title=x.元素(“title”).值,
link=x.元素(“link”).值,
pubDate=x.Element(“pubDate”).值,
描述=x.元素(“描述”).值
});
如果(项!=null)
{
foreach(项目中的var i)
{
饲料f=新饲料
{
Title=i.Title,
Link=i.Link,
PublishDate=i.PublishDate,
描述
};
添加(f);
}
}
返回视图(提要);
以下是我面临的问题:

  • 如何确保RSS提要具有全文描述和所有 媒体文件
  • 如何解析媒体文件
  • 如何向用户显示媒体文件 理想的工作场所
  • 条件


    我希望我的要求是明确的。请分享建议。

    这不相关,但条件
    items!=null
    总是正确的。您不需要它。您可以更改查询并直接创建
    Feed
    列表:使用
    选择新Feed{..}
    而不是
    选择new
    并在查询结束时添加一个
    列表。#selman 22感谢您的回复。我共享的代码工作正常,但我不知道如何使用它解析媒体文件。我的主要动机是从rss提要获取媒体元素并将其显示到所需位置。。
    
      string RssFeedUrl = "RSSFeedURL HERE";
    
            List<Feed> feeds = new List<Feed>();
            try
            {
                XDocument xDoc = new XDocument();
                xDoc = XDocument.Load(RssFeedUrl);
                var items = (from x in xDoc.Descendants("item")
                             select new
                             {
                                 title = x.Element("title").Value,
                                 link = x.Element("link").Value,
                                 pubDate = x.Element("pubDate").Value,
                                 description = x.Element("description").Value
                             });
                if (items != null)
                {
                    foreach (var i in items)
                    {
                        Feed f = new Feed
                        {
                            Title = i.title,
                            Link = i.link,
                            PublishDate = i.pubDate,
                            Description = i.description
                        };
    
                        feeds.Add(f);
                    }
                }
    
                return View(feeds);