ASP. NET reads RSS, asp. netrss

Source: Internet
Author: User

ASP. NET reads RSS, asp. netrss
A piece of code for reading RSS from the Internet can be used after testing:
C # code

  1. /// <Summary>
  2. /// Load RSS
  3. /// </Summary>
  4. /// <Param name = "RssUrl"> RSS address </param>
  5. /// <Param name = "RssCount"> Number of articles to be extracted </param>
  6. /// <Returns> </returns>
  7. Public string LoadRSS (string RssUrl, int RssCount)
  8. {
  9. XmlDocument doc = new XmlDocument ();
  10. String Rss = "";
  11. If (RssUrl! = "")
  12. {
  13. Try
  14. {
  15. Doc. Load (RssUrl );
  16. XmlNodeList nodelist = doc. GetElementsByTagName ("item ");
  17. XmlNodeList objItems1;
  18. Int I = 1;
  19. If (doc. HasChildNodes)
  20. {
  21. Foreach (XmlNode node in nodelist)
  22. {
  23. String title = ""; // document title
  24. String link = ""; // link
  25. String content = ""; // content
  26. String createDate = ""; // posting time
  27. I + = 1;
  28. If (node. HasChildNodes)
  29. {
  30. ObjItems1 = node. ChildNodes;
  31. Foreach (XmlNode node1 in objItems1)
  32. {
  33. Switch (node1.Name)
  34. {
  35. Case "title ":
  36. Title = node1.InnerText;
  37. Break;
  38. Case "link ":
  39. Link = node1.InnerText;
  40. Break;
  41. Case "description ":
  42. Content = node1.InnerText;
  43. Break;
  44. Case "pubDate ":
  45. CreateDate = node1.InnerText;
  46. Break;
  47. }
  48. If (title! = "" & Link! = "")
  49. Break;
  50. }
  51. Rss + = "<a href = '" + link + "'target =' _ blank '>" + title + "</a> posted on" + createDate + "
  52. Rss + = content;
  53. }
  54. If (I> RssCount)
  55. Break;
  56. }
  57. }
  58. }
  59. Catch (Exception)
  60. {
  61. Rss = "RSS Feed source data error! ";
  62. }
  63. }
  64. Else
  65. {
  66. Rss = "No information source found. You can refresh and try again or contact the administrator! ";
  67. }
  68. Return Rss;
  69. }
 
How does ASPNET read online RSS content?

Webclient and other requests can be directly downloaded.
Rss itself is an xml file and can be parsed manually. It is also very simple.
It seems that no ready-made components are currently available.
 
How does RSS aspnet implement its subscription?

Xml Solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.