c# - 使用 syndicationitem 获取自定义 rss 提要项目元素?

标签 c#

我有一个像这样的 RSS 提要:

<item>
<title>
Ellen celebrates the 20th anniversary of coming out episode
</title>
<link>
http://www.dailymail.co.uk/video/tvshowbiz/video-1454179/Ellen-celebrates-20th-anniversary-coming-episode.html?ITO=1490&ns_mchannel=rss&ns_campaign=1490
</link>
<description>
Ellen celebrates 20th anniversary of coming out episode on her old sitcom 'Ellen'. Ellen said she cried during rehearsals but urged everyone to stay true to themselves and it will benefit you in the long term.
</description>
<enclosure url="http://i.dailymail.co.uk/i/pix/2017/04/27/00/3FA409EA00000578-0-image-m-21_1493249529333.jpg" type="image/jpeg" length="7972"/>
<pubDate>Thu, 27 Apr 2017 00:45:14 +0100</pubDate>
<guid>
http://www.dailymail.co.uk/video/tvshowbiz/video-1454179/Ellen-celebrates-20th-anniversary-coming-episode.html?ITO=1490&ns_mchannel=rss&ns_campaign=1490
</guid>
<media:description/>
<media:thumbnail url="http://i.dailymail.co.uk/i/pix/2017/04/27/00/3FA409EA00000578-0-image-m-21_1493249529333.jpg" width="154" height="115"/>
<media:credit scheme="urn:ebu">YouTube</media:credit>
<media:content url="http://video.dailymail.co.uk/video/mol/2017/04/26/4464646762446275941/1024x576_MP4_4464646762446275941.mp4" type="video/mp4" medium="video" duration="245" lang="en"/>
</item>

我正在尝试获取 media:content 的 url 值,当我像这样遍历联合项目时:

            foreach (SyndicationItem item in feed.Items)
            {

                foreach (SyndicationElementExtension extension in item.ElementExtensions)
                {
                    XElement ele = extension.GetObject<XElement>();
                    MessageBox.Show(ele.Value);
                }


            }

我得到的是空白数据,如何获取媒体内容的url?

最佳答案

你试过吗:

XElement ele = extension.GetObject<XElement>();
if (ele.Name.LocalName == "content")
{
   MessageBox.Show(ele.Attribute("url").Value);
}

关于c# - 使用 syndicationitem 获取自定义 rss 提要项目元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43646613/

相关文章:

c# - .NET 世界是否有日志外观?

c# - 如何制作 If 语句来检查 textBox1.Text 是否包含字符串 reply = client.DownloadString (address);适本地?

c# - 如何获得使用类变量的方法调用

c# - 列表框中的扩展器在折叠时留下空白

c# - 如何为子级TreeView节点设置父级值

c# - 主类中的 "string[] args"是做什么用的?

c# - MonoDevelop 中的 XML 注释

c# - 解决 LINQ to Entities 无法识别该方法的方法?

c# - 迭代 lambda 表达式的属性

c# - 我可以向 CaSTLe Windsor 指定要在类代理中覆盖哪些虚拟方法吗?