如何访问媒体的url attr:缩略图和媒体:RSS Feed中的内容元素?
问题描述:
我正在尝试使用我的Zenfolio RSS提要,以便我可以在提要中显示图像。我如何访问媒体的url值:缩略图和媒体:RSS提要中的内容元素?我搜索了高低,并没有找到关于如何访问url值的答案。有一个类似的未答复的SO post。如何访问媒体的url attr:缩略图和媒体:RSS Feed中的内容元素?
的元件的例子:
<media:thumbnail url="http://riderdesign.net/img/s11/v35/p449020235-2.jpg"
width="400"
height="225"
/>
<media:content url="http://riderdesign.net/img/s11/v35/p449020235-2.jpg"
type="image/jpeg" medium="image"
width="400"
height="225"
/>
我在我的控制器的代码:
Public Function Feed() As ActionResult
Dim feedurl As String = "http://riderdesign.net/recent.rss"
Using x = XmlReader.Create(feedurl)
Dim r As SyndicationFeed = SyndicationFeed.Load(x)
Return View(r)
End Using
End Function
我认为我有@ModelType System.ServiceModel.Syndication.SyndicationFeed和
@For Each i In ViewData.Model.Items
@i.Title.text @<br />
<!--What do i do here to get the url values?-->
Next
答
我有我的解决方案。我会在这里发布代码。
代码:
Public Function Feed() As ActionResult
Dim feedurl As String = "http://riderdesign.net/p319394411/recent.rss"
Using x = XmlReader.Create(feedurl)
Dim r = XDocument.Load(x)
Dim mediapfx As XNamespace = "http://search.yahoo.com/mrss/"
Dim ml = From item In r.Descendants(mediapfx + "content") Select item
Dim medialist = From item In r.Descendants("item") Select New MediaImage With {
.Id = item.Element("guid").Value, .ImageUrl = TryGetAttributeValue(item.Element(mediapfx + "content"), "url")} Take 5
Return View(medialist)
End Using
End Function
Private Function TryGetAttributeValue(ByVal xe As XElement, ByVal attribute As String) As String
If xe IsNot Nothing AndAlso xe.Attribute(attribute) IsNot Nothing Then
Return xe.Attribute(attribute).Value
Else
Return Nothing
End If
End Function
Namespace RiderDesignMvcBlog.Core.ViewModels
Public Class MediaImage
Public Property Id() As String
Public Property ImageUrl() As String
End Class
End Namespace
鉴于:
@ModelType IEnumerable(Of RiderDesignMvcBlog.Core.ViewModels.MediaImage)
@Code
ViewData("Title") = "Feed"
Layout = "~/Views/Shared/_Layout4.vbhtml"
End Code
<h2>Feed</h2>
@For Each i In Model
@<img src=" @i.ImageUrl" />
Next
您可以使用XPath或WCF的RSS对象分析呢? – LamonteCristo