Getting the right node in Linq to XML

ZSkarly

New Member
Im trying to parse an XML file containing all the uploaded videos on a certain channel. Im attempting to get tbe value of the URL attribute in one of the \[code\]<media:content>\[/code\] nodes and put it in the ViewerLocation field. However there are several of them. My current code is this:\[code\]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};\[/code\]It gets me the first node in the XML for entry with the name \[code\]<media:content>\[/code\] as you would expect. However, the first entry in the XML isn't what I want. I want the second. Below is the relevant XML.\[code\]<!-- 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'/>\[/code\]I want the second node because it has a type of 'video/3gpp'. How would I go about selecting that one? My logic would be if attribute(type == "video/3gpp") get this value.But i do not know how to express this in Linq.Thanks,Danny.
 
Back
Top