我试图解析包含某个频道上所有上传视频的 XML 文件。我试图在其中一个<media:content>
节点中获取 URL 属性的值并将其放在 ViewerLocation 字段中。但是有几个。我目前的代码是这样的:
var videos = from xElem in xml.Descendants(atomNS + "entry")
select new YouTubeVideo()
{
Title = xElem.Element(atomNS + "title").Value,
Description = xElem.Element(atomNS + "content").Value,
DateUploaded = xElem.Element(atomNS + "published").Value,
ThumbnailLocation = xElem.Element(mediaNS + "group").Element(mediaNS + "content").Attribute("url").Value,
ViewerLocation = xElem.Element(mediaNS + "group").Element(mediaNS + "content").Attribute("url").Value
};
它为我提供了 XML 中的第一个节点,用于输入<media:content>
您所期望的名称。但是,XML 中的第一个条目不是我想要的。我想要第二个。
下面是相关的 XML。
<!-- I currently get the value held in this node -->
<media:content
url='http://www.youtube.com/v/ZTUVgYoeN_b?f=gdata_standard...'
type='application/x-shockwave-flash' medium='video'
isDefault='true' expression='full' duration='215' yt:format='5'/>
<!-- What i actually want is this one -->
<media:content
url='rtsp://rtsp2.youtube.com/ChoLENy73bIAEQ1kgGDA==/0/0/0/video.3gp'
type='video/3gpp' medium='video'
expression='full' duration='215' yt:format='1'/>
<media:content
url='rtsp://rtsp2.youtube.com/ChoLENy73bIDRQ1kgGDA==/0/0/0/video.3gp'
type='video/3gpp' medium='video'
expression='full' duration='215' yt:format='6'/>
我想要第二个节点,因为它具有“video/3gpp”类型。我将如何选择那个?我的逻辑是
if attribute(type == "video/3gpp") 得到这个值。
但我不知道如何在 Linq 中表达这一点。
谢谢,
丹尼。