create RSS reader in ASP.NET
-
12-12-2019 - |
Question
I use VS2010, C# I want to read RSS content from other sites and display them in my site, currently this process is performed manually (site admin searches other sites and copy/pastes related content in news items!), but I want to do it automatically and I think the best solution is RSS, I've tried several sample codes but none of them worked, is there an easy way to implement RSS reader in ASP.NET? what are my options here?
Solution
Read RSS Link
public void ReadDoc(XmlDocument rssDoc)
{
XmlNode nodeRss = null;
XmlNode nodeChannel = null;
XmlNode nodeItem = null;
try
{
if (rssDoc == null)
{
return;
}
// Loop for the <rss> tag
for (int i = 0; i < rssDoc.ChildNodes.Count; i++)
{
// If it is the rss tag
if (rssDoc.ChildNodes[i].Name == "rss")
{
nodeRss = rssDoc.ChildNodes[i];
break;
}
}
if (nodeRss == null)
{
return;
}
for (int i = 0; i < nodeRss.ChildNodes.Count; i++)
{
if (nodeRss.ChildNodes[i].Name == "channel")
{
nodeChannel = nodeRss.ChildNodes[i];
break;
}
}
if (nodeChannel == null)
{
return;
}
// Loop for the <title>, <link>, <description> and all the other tags
for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)
{
if (nodeChannel.ChildNodes[i].Name == "item")
{
nodeItem = nodeChannel.ChildNodes[i];
if (nodeItem["title"] != null){}
if (nodeItem["description"] != null){}
if (nodeItem["pubDate"] != null){}
}
}
}
catch (Exception)
{
throw;
}
finally
{
nodeRss = null;
nodeChannel = null;
nodeItem = null;
}
}
public void CreateRSS(String Path)
{
XmlDocument doc = null;
XmlTextReader rssReader = null;
Label doclbl = null;
Label snolbl = null;
try
{
try
{
rssReader = new XmlTextReader(Path);
}
catch (Exception)
{
return;
}
if (rssReader == null)
{
return;
}
doc = new XmlDocument();
try
{
doc.Load(rssReader);
}
catch (Exception)
{
return;
}
if (doc == null)
{
return;
}
ReadDoc(doc);
}
catch (Exception)
{
throw;
}
finally
{
doc = null;
rssReader = null;
doclbl = null;
snolbl = null;
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow