I wrote a code to read RSS feed that works fine. If you access this URL you will see that it returns an XML in the browser, but when running in my code it generates an internal error in the server and I do not understand why. Can someone help me?
The code below is in dotNetFeedle . If you uncomment the second link and comment the first you can see the error.
using System;
using System.Xml;
public class Program
{
public static void Main()
{
string urlXml = "http://g1.globo.com/dynamo/tecnologia/rss2.xml";
//string urlXml = @"http://migalhas.com.br/rss/rss.xml";
//Cria novo documento XML local
XmlDocument doc = new XmlDocument();
//Tenta Carregar XML remoto em nosso XML local
try
{
doc.Load(urlXml);
XmlNodeList rssItems = doc.SelectNodes("//item");
int i = 0;
foreach (XmlNode node in rssItems)
{
i++;
Console.WriteLine(i + " - " + node["title"].InnerText);
if(i==5)
break;
}
}
catch (Exception ex)
{
Console.WriteLine("Erro:" + ex.Message);
}
//Selcecionar nós desejados usando xPath
}
}