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];
}
}
上面的代码对于大多数 rss 提要都可以正常工作,但是我在执行最后一个循环时遇到了 nullrefrence 异常。我应该怎么做才能让它工作?