try
{
rssDoc = new XmlDocument();
// Load the XML context into XmlDocument
rssDoc.Load(rssReader);
MessageBox.Show(rssDoc.ToString());
}
catch (Exception ex)
{
errorProvider1.SetError(url, "Cannot load the RSS from this url");
}
// Loop for <rss> tag in xmldocument
for (int i = 0; i < rssDoc.ChildNodes.Count; i++)
{
// If <rss> tag found
if (rssDoc.ChildNodes[i].Name == "rss")
{
// assign the <rss> tag node to nodeRSS
nodeRss = rssDoc.ChildNodes[i];
}
}
//Loop for the <channel> tag in side <rss> tag stored in nodeRss
for (int i = 0; i < nodeRss.ChildNodes.Count; i++) <<<<<<EXCEPTION
{
// <channel> node found
if (nodeRss.ChildNodes[i].Name == "channel")
{
//assign the <channel> tag to nodeChannel
nodeChannel = nodeRss.ChildNodes[i];
}
}
Above code is working fine for most of the rss feeds but I am getting a nullrefrence exception while going through the last loop.
What should i do to make it work?
Why reinvent the wheel?
…should do the trick. (I’m pretty sure RSS only allows a single
channelelement inside the rootrsselement. Otherwise, look atSelectNodes()rather thanSelectSingleNode().)