public void LoadRSS(string heading, string url) { if (!string.IsNullOrEmpty(url)) { try { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; WebClient client = new WebClient(); Uri uri = new Uri(url); string xml = ""; using (StreamReader reader = new StreamReader(client.OpenRead(uri), System.Text.Encoding.GetEncoding(1252))) { xml = reader.ReadToEnd(); } Items.Clear(); OriginalRssItems.Clear(); ParseRssXml(xml, false); //ParseRssXml(xml1, false); SetRssToTickerControl(); } catch (Exception ex) { throw ex; } } }
public void ParseRssXml(string xml, bool IsTop = false) { try { SyndicationFeed feed = new SyndicationFeed(); byte[] byteArray = Encoding.GetEncoding(1252).GetBytes(xml); MemoryStream stream = new MemoryStream(byteArray); using (stream) { XmlTextReader xmlReader = new XmlTextReader(stream); feed = SyndicationFeed.Load(xmlReader); } Items.Clear(); OriginalRssItems.Clear(); if (!IsTop) { foreach (SyndicationItem item in feed.Items) { PopulateFeed(item); if (Items.Count == m_RSSMaxItems) { break; } } } else { PopulateFeed(feed.Items.First()); } Source = new RSSSource(); if (feed.Title != null) { Source.Title = feed.Title.Text; } if (feed.Description != null) { Source.Description = feed.Description.Text; } } catch (Exception ex) { throw (ex); } }