gpt4 book ai didi

c# - 使用C#XMLDocument读取YouTube channel XML文件

转载 作者:行者123 更新时间:2023-12-03 05:41:59 35 4
gpt4 key购买 nike

我想从 channel 的rss feed中获取 channel 信息和文件列表。例如,
http://gdata.youtube.com/feeds/api/users/google/uploads
是Google的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>

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

最佳答案

试试这个:

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;
}

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

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

关于c# - 使用C#XMLDocument读取YouTube channel XML文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18324231/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com