ASP. NET reads RSS, asp. netrss
A piece of code for reading RSS from the Internet can be used after testing:
C # code
- /// <Summary>
- /// Load RSS
- /// </Summary>
- /// <Param name = "RssUrl"> RSS address </param>
- /// <Param name = "RssCount"> Number of articles to be extracted </param>
- /// <Returns> </returns>
- Public string LoadRSS (string RssUrl, int RssCount)
- {
- XmlDocument doc = new XmlDocument ();
- String Rss = "";
- If (RssUrl! = "")
- {
- Try
- {
- Doc. Load (RssUrl );
- XmlNodeList nodelist = doc. GetElementsByTagName ("item ");
- XmlNodeList objItems1;
- Int I = 1;
- If (doc. HasChildNodes)
- {
- Foreach (XmlNode node in nodelist)
- {
- String title = ""; // document title
- String link = ""; // link
- String content = ""; // content
- String createDate = ""; // posting time
- I + = 1;
- If (node. HasChildNodes)
- {
- ObjItems1 = node. ChildNodes;
- Foreach (XmlNode node1 in objItems1)
- {
- Switch (node1.Name)
- {
- Case "title ":
- Title = node1.InnerText;
- Break;
- Case "link ":
- Link = node1.InnerText;
- Break;
- Case "description ":
- Content = node1.InnerText;
- Break;
- Case "pubDate ":
- CreateDate = node1.InnerText;
- Break;
- }
- If (title! = "" & Link! = "")
- Break;
- }
- Rss + = "<a href = '" + link + "'target =' _ blank '>" + title + "</a> posted on" + createDate + "
- Rss + = content;
- }
- If (I> RssCount)
- Break;
- }
- }
- }
- Catch (Exception)
- {
- Rss = "RSS Feed source data error! ";
- }
- }
- Else
- {
- Rss = "No information source found. You can refresh and try again or contact the administrator! ";
- }
- Return Rss;
- }
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