Assimilate XML RSS Feed from URL in C#
This piece of code pulls an RSS feed and displays the title of the articles. It is here to demonstrate just how easy it is to pull XML off the web and utilize the data.
I use Trace.WriteLine instead of Console.WriteLine so the report is fed to the Visual Studio output window and can be run as either a Console or Windows app, but at least a new Console window is not opened.
|
using System.Xml;
using System.Net;
using System.Text;
using System.Diagnostics;
// -------------------------------
// RSS XML Feed URL
string url = "http://msmvps.com/coad/rss.aspx";
// Create an interface to the web
WebClient c = new WebClient();
// Download the XML into a string
string xml = ASCIIEncoding.Default.GetString(c.DownloadData(url));
// Document to contain the feed
XmlDocument doc = new XmlDocument();
// Parse the xml
doc.LoadXml(xml);
// Display each article title
foreach (XmlNode node in doc.SelectNodes("/rss/channel/item/title"))
Trace.WriteLine(node.InnerText);
|