1
votes

I want to get the channel information and list of files from the rss feed for a channel. For instance, http://gdata.youtube.com/feeds/api/users/google/uploads is the rss feed for google. How would I get the title for the feed, for instance? Or the list of videos? I tried

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

But xn is always returning null. I also tried "/title", "feed/title", and "title", none of which worked. Similarly for the list of videos, I tired

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

And a few other permutations without success.

(Edit adding the xml info so no one will have to click on the link)

Here's what the top of the xml file looks like:

<?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>

I just want to know how to get a value out of there, such as the title or the id

1

1 Answers

0
votes

Try this:

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");