What I'm trying to do here is get an RSS feed and append an Enclosure XML node to each item, which has a link to a video file (wmv).Try the below code withurl = http://www.microsoft.com/events/series/digitalblackbelt.aspx?tab=rssfor eg to get the pointThe performance hit here consists of two parts: the LONG foreach loop, along with the HUGE number of requests done to retrieve the media link (marked in the code by the comment This part needs attention). Any advice concerning how to get the media link a much faster manner would really be appreciated!You can get a glimpse of what that code do, by comparing this feed (the URL):http://www.microsoft.com/events/series/digitalblackbelt.aspx?tab=rssto this feed (created by the code below), note that it will be slow and might give error, if it did just refresh the page:http://mshady.apphb.com/feeds/index?url=http://www.microsoft.com/events/series/digitalblackbelt.aspx?tab=rsspublic class FeedsController : Controller{    private XmlDocument _Xml;    [OutputCache(VaryByParam = url, Duration=86400)]        public string Index(string url)    {        string feed = ;        _Xml = new XmlDocument();        _Xml.Load(url);        foreach (XmlNode node in _Xml.ChildNodes[0].ChildNodes[0].ChildNodes)        {            if (node.Name == item)            {                XmlNode childnode = GetEnclosureXmlNode(node);                node.AppendChild(childnode);            }        }        feed =  _Xml.OuterXml;        return feed;    }    private string GetMediaUrl(string articleUrl)    {        string mediaUrl = ;        ////////////////////////////////////////////            // This part needs attention        ////////////////////////////////////////////            Regex regex = new Regex(@<a href=(.*?)>WMV Download</a>);        var request = HttpWebRequest.Create(articleUrl);        var response = request.GetResponse();        string responseHtml = new StreamReader(response.GetResponseStream()).ReadToEnd();        var match = regex.Match(responseHtml);        ////////////////////////////////////////////            // This part needs attention        ////////////////////////////////////////////            if (match.Success)            mediaUrl = match.Groups[1].Value;        return mediaUrl;    }    private XmlNode GetEnclosureXmlNode(XmlNode node)    {        string articleUrl = node[link].InnerText;        string mediaUrl = GetMediaUrl(articleUrl);        XmlElement childnode = CreateEnclosureXmlNode(mediaUrl);        return childnode;    }    private XmlElement CreateEnclosureXmlNode(string mediaUrl)    {        XmlElement childnode = _Xml.CreateElement(enclosure);        childnode.SetAttribute(url, mediaUrl);        childnode.SetAttribute(type, video/wmv);        return childnode;    }}
A faster way to look up for a url in a WebRequest/WebResponse html
c#;performance;regex