使用c#xmldocument读取youtube通道xml文件

时间:2013-08-19 22:37:15

标签: c# xml youtube youtube-api

我想从频道的RSS订阅源获取频道信息和文件列表。例如, http://gdata.youtube.com/feeds/api/users/google/uploads 是谷歌的rss饲料。例如,我如何获得Feed的标题?还是视频列表?我试过了

WebClient wc = new WebClient();
XmlDocument xd = new XmlDocument();
xd.LoadXml(wc.DownloadString(strUrl));
XmlNode xn = xd.SelectSingleNode("/feed/title");

但是xn总是返回null。我也试过“/ title”,“feed / title”和“title”,但都没有。同样,对于视频列表,我累了

XmlNodeList vids = xd.SelectNodes("/entry");

还有一些其他的排列没有成功。

(编辑添加xml信息,以便没有人必须点击链接)

以下是xml文件的顶部:

<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" 
      xmlns:gd="http://schemas.google.com/g/2005" 
      xmlns:yt="http://gdata.youtube.com/schemas/2007">
    <id>http://gdata.youtube.com/feeds/api/users/google/uploads</id>
    <updated>2013-08-19T21:47:34.674Z</updated>
    <category scheme="http://schemas.google.com/g/2005#kind" 
              term="http://gdata.youtube.com/schemas/2007#video" />
    <title type="text">Uploads by Google</title>
    <logo>http://www.gstatic.com/youtube/img/logo.png</logo>
</feed>

我只想知道如何从中获取值,例如标题或ID

1 个答案:

答案 0 :(得分:0)

试试这个:

XmlDocument xml = new XmlDocument();
xml.LoadXml(wc.DownloadString(strUrl)); 

XmlNodeList xnList = xml.SelectNodes("/Feed/Title");
foreach (XmlNode xn in xnList)
{
  string Title= xn["Title"].InnerText;
}

OR

var doc = XDocument.Load(wc.DownloadString(strUrl));

string result = (string)doc.Root.Element("Title");