XmlNodeList videos = doc.GetElementsByTagName("entry");
foreach (XmlNode video in videos)
{
string videoId = video["id"].InnerText.Replace("http://gdata.youtube.com/feeds/api/videos/", String.Empty);
string author = video["author"]["name"].InnerText;
string views = video["yt:statistics"].Attributes["viewCount"].Value;
Console.WriteLine(videoId);
Console.WriteLine(author);
Console.WriteLine(views);
}
Reading XML with a colon (:)
-
28-06-2023 - |
Vra
I'm trying to get the views of a video from the following XML document (https://gdata.youtube.com/feeds/api/videos?q=example), I'm able to get the link and the autor because there is no colon in the tag.
I'm trying to get yt:statistics but I've no idea how.
result = e.Result.Replace("xmlns='http://www.w3.org/2005/Atom' ", String.Empty);
XmlDocument doc = new XmlDocument();
doc.LoadXml(result);
XmlNodeList videos = doc.GetElementsByTagName("entry");
foreach (XmlNode video in videos)
{
XmlNode insideauthor = video.SelectSingleNode("author");
string videoId = video.SelectSingleNode("id").InnerText.Replace("http://gdata.youtube.com/feeds/api/videos/", String.Empty);
string author = insideauthor.SelectSingleNode("name").InnerText;
// Trying to get the views of a video of the search results
MessageBox.Show(video.SelectSingleNode("yt:statistics").Attributes["viewCount"].InnerText);
}
Oplossing
Gelisensieer onder: CC-BY-SA met toeskrywing
Nie verbonde aan StackOverflow