private bool LoadXMLRSS1_0(PodcastFeed sub, string rss, uint maxItems) { bool success = true; try { var xmlDocument = new XmlDocument(); var bytes = Encoding.UTF8.GetBytes(rss); using (var stream = new MemoryStream(bytes)) { xmlDocument.Load(stream); } var channels = xmlDocument.GetElementsByTagName("channel"); foreach (XmlElement channel in channels) { int count = 0; sub.Title = GetXmlElementValue(channel, "title"); sub.Description = GetXmlElementValue(channel, "description"); sub.SiteLink = GetXmlElementValue(channel, "link"); var items = channel.GetElementsByTagName("item"); foreach (XmlNode item in items) { if (count++ >= maxItems) { break; } string itemTitle = GetXmlElementValue(item, "title"); PodcastEpisode it = sub.PodcastEpisodes.FirstOrDefault(i => i.Title == itemTitle); bool noItem = it == null; if (noItem) { it = new PodcastEpisode(); it.Title = itemTitle; } it.Title = itemTitle; it.Description = GetXmlElementValue(item, "description"); it.Link = GetXmlElementValue(item, "link"); it.Guid = GetXmlElementValue(item, "guid"); it.PubDate = GetXmlElementValue(item, "pubDate"); it.RowNum = count; it.ParentFeed = sub; sub.ItemsLoaded = true; it.IsLoaded = true; sub.PodcastEpisodes.Add(it); } } } catch (Exception ex) { OnError(ex.ToString()); success = false; } sub.HasErrors = !success; return(success); }
private bool LoadXMLAtom(PodcastFeed sub, string rss, uint maxItems) { bool success = true; try { var doc = new XmlDocument(); doc.LoadXml(rss); var feedNode = doc["feed"]; sub.Title = GetXmlElementValue(feedNode, "title"); if (string.IsNullOrEmpty(sub.ImageUrl)) { sub.ImageUrl = GetXmlElementValue(feedNode, "icon"); } var entries = feedNode.GetElementsByTagName("entry"); int count = 0; foreach (XmlNode entry in entries) { if (count++ >= maxItems) { break; } string itemTitle = GetXmlElementValue(entry, "title"); PodcastEpisode it = sub.PodcastEpisodes.FirstOrDefault(i => i.Title == itemTitle); bool noItem = it == null; if (noItem) { it = new PodcastEpisode(); it.Title = itemTitle; } it.Title = itemTitle; it.Description = GetXmlElementValue(entry, "summary"); it.PubDate = GetXmlElementValue(entry, "updated"); it.Link = GetXmlAttribute(entry["link"], "href"); it.RowNum = count; it.ParentFeed = sub; sub.ItemsLoaded = true; it.IsLoaded = true; sub.PodcastEpisodes.Add(it); } } catch (Exception ex) { OnError(ex.ToString()); success = false; } sub.HasErrors = !success; return(success); }
private bool LoadXMLRSS2_0(PodcastFeed sub, string rss, uint maxItems) { bool success = true; try { var xmlDocument = new XmlDocument(); var bytes = Encoding.UTF8.GetBytes(rss); using (var stream = new MemoryStream(bytes)) { xmlDocument.Load(stream); } var channels = xmlDocument.GetElementsByTagName("channel"); foreach (XmlElement channel in channels) { int counter = 0; sub.Title = GetXmlElementValue(channel, "title"); sub.SiteLink = GetXmlElementValue(channel, "link"); sub.Description = GetXmlElementValue(channel, "description"); sub.PubDate = GetXmlElementValue(channel, "pubDate"); sub.Ttl = GetXmlElementValue(channel, "ttl"); sub.LastBuildDate = GetXmlElementValue(channel, "lastBuildDate"); if (string.IsNullOrEmpty(sub.ImageUrl)) { var imageNodes = channel.GetElementsByTagName("image"); if (imageNodes.Count > 0) { var imageNode = imageNodes[0]; sub.ImageUrl = GetXmlElementValue(imageNode, "url"); } } var items = channel.GetElementsByTagName("item"); foreach (XmlNode item in items) { if (counter++ >= maxItems) { break; } string itemTitle = GetXmlElementValue(item, "title"); PodcastEpisode it = sub.PodcastEpisodes.FirstOrDefault(i => i.Title == itemTitle); bool noItem = it == null; if (noItem) { it = new PodcastEpisode(); it.Title = itemTitle; } it.Link = GetXmlElementValue(item, "link"); if (item["enclosure"] != null) { it.Link = GetXmlAttribute(item["enclosure"], "url"); } it.Description = processDescription(GetXmlElementValue(item, "description")); it.Guid = GetXmlElementValue(item, "guid"); it.PubDate = GetXmlElementValue(item, "pubDate"); string durationString; if (TryGetXmlElementValue(item, "itunes:duration", out durationString)) { TimeSpan durationTimeSpan; if (TimeSpan.TryParse(durationString, out durationTimeSpan)) { it.DurationMs = (int)durationTimeSpan.TotalMilliseconds; } } it.RowNum = counter; it.ParentFeed = sub; it.IsLoaded = true; sub.ItemsLoaded = true; if (noItem) { sub.PodcastEpisodes.Add(it); } } } } catch (Exception ex) { OnError(ex.ToString()); success = false; } sub.HasErrors = !success; return(success); }