Создать RSS Reader в ASP.NET
-
12-12-2019 - |
Вопрос
Я использую vs2010, c # Я хочу прочитать RSS-контент с других сайтов и отображать их на моем сайте, в настоящее время этот процесс выполняется вручную (сайт администратора поиск других сайтов и копирование / пассы, связанные с контентом в новостях!), Но яХотите сделать это автоматически, и я думаю, что лучшее решение RSS, я попробовал несколько образцов кодов, но ни один из них не работал, есть ли простой способ реализации RSS Reader в ASP.NET?Какие мои варианты здесь?
Решение
Читайте ссылку RSS
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;
}
}
.
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;
}
}
Не связан с StackOverflow