我试图从youtube播放列表中获取YouTube视频的说明。
xml播放列表看起来像这样:
<entry gd:etag="W/"YhjhqeyM."">
<title>My Title</title>
<media:group>
<media:description type="plain">My description</media:description>
</media:group>
</entry>
.
.
.
...multiple entry elements
我循环遍历多个条目并获得标题:
var x = (from e in xmlFeed.Root.Elements().Where(n => n.Name.LocalName == "entry") select e);
foreach (XElement element in x)
{
title = element.Elements().Where(n => n.Name.LocalName == "title").FirstOrDefault().Value;
description = //??;
}
如何获得上述格式的描述?
由于
答案 0 :(得分:0)
description = element.Descendants(XName.Get("description")).First().Value();
答案 1 :(得分:0)
这样做,由你自己如何加载你的文档。在这种情况下,我使用HttpWebRequest
/ StreamReader
阅读了它:
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(requestData("https://gdata.youtube.com/feeds/api/playlists/63F0C78739B09958?v=2"));
var node = doc.DocumentNode.Descendants("media:description").ToList();
foreach (var description in node)
{
Response.Write(string.Format("Description: {0}\n",description.InnerText.ToString()));
}
答案 2 :(得分:0)
XDocument xDoc = XDocument.Load("https://gdata.youtube.com/feeds/api/playlists/63F0C78739B09958?v=2");
XNamespace media = XNamespace.Get("http://search.yahoo.com/mrss/");
var descs = xDoc.Descendants(media + "description")
.Select(d => d.Value)
.ToArray();