private void AppcastWasDownloaded(Object sender, DownloadStringCompletedEventArgs e) { if (e.Error != null) { ReportError(e.Error); } else { XmlNodeList xmlItems = null; try { XmlDocument doc = new XmlDocument(); doc.LoadXml(e.Result); xmlItems = doc.SelectNodes("/rss/channel/item"); } catch (Exception ex) { ReportError(ex); return; } List <SUAppcastItem> appcastItems = new List <SUAppcastItem>(); foreach (XmlNode node in xmlItems) { Dictionary <string, ArrayList> nodesDict = new Dictionary <string, ArrayList>(); Dictionary <string, Object> itemDescription = new Dictionary <string, object>(); // Create a dictionary of nodes for each name present, // so we can parse by xml:lang later. foreach (XmlNode childNode in node.ChildNodes) { string nodeName = childNode.Name; ArrayList nodesForName = null; if (!nodesDict.TryGetValue(nodeName, out nodesForName)) { nodesForName = new ArrayList(); nodesDict.Add(nodeName, nodesForName); } nodesForName.Add(childNode); } foreach (string itemKey in nodesDict.Keys) { ArrayList nodes = null; nodesDict.TryGetValue(itemKey, out nodes); XmlNode bestNodeForKey = BestNodeInNodes(nodes); if (bestNodeForKey.Name.Equals("enclosure")) { // enclosure is flattened as a separate dictionary for some reason Dictionary <string, string> enclosureDict = new Dictionary <string, string>(); foreach (XmlAttribute attribute in bestNodeForKey.Attributes) { enclosureDict.SetValueForKey(attribute.InnerText, attribute.Name); } itemDescription.SetValueForKey(enclosureDict, "enclosure"); } else if (bestNodeForKey.Name.Equals("pubDate")) { try { DateTime date = DateTime.Parse(bestNodeForKey.InnerText); itemDescription.SetValueForKey(date, bestNodeForKey.Name); } catch { // Nothing } } else { itemDescription.SetValueForKey(bestNodeForKey.InnerText.Trim(), bestNodeForKey.Name); } } try { SUAppcastItem item = new SUAppcastItem(itemDescription); appcastItems.Add(item); } catch { } } appcastItems.Sort(); appcastItems.Reverse(); // new to old Items = appcastItems; if (Delegate != null) { Delegate.AppcastDidFinishLoading(this); } } }