Wednesday, July 13, 2011

Get XML from RSS

To get the XML from an RSS feed, view the source of the page. Programmatically, the following can be used:
HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(url);

httpReq.Method = @"GET";
httpReq.ContentType = @"text/xml";
httpReq.Timeout = 600000;
httpReq.KeepAlive = false;

HttpWebResponse resp = (HttpWebResponse)httpReq.GetResponse();
StreamReader srdr = new StreamReader(resp.GetResponseStream(), Encoding.GetEncoding("UTF-8"));
string xmlstr = srdr.ReadToEnd();
resp.Close();

At this point, the XML is in the string xmlstr, this can then be loaded into an XML document or utilized as is.