public void addArticle(Article article) { articles.Add(article); }
public static List<Channel> getFeedFromFile(string fileSource) { List<Channel> channelList = new List<Channel>(); try { XmlDocument doc = new XmlDocument(); doc.Load(fileSource); XmlNodeList nodeList; XmlNode root = doc.DocumentElement; nodeList = root.ChildNodes; foreach (XmlNode chanel in nodeList) { Channel channel = new Channel(); foreach (XmlNode chanel_item in chanel) { if (chanel_item.Name == "title") { channel.info.title = chanel_item.InnerText; } if (chanel_item.Name == "description") { channel.info.description = chanel_item.InnerText; } if (chanel_item.Name == "copyright") { channel.info.copyright = chanel_item.InnerText; } if (chanel_item.Name == "link") { channel.info.link = chanel_item.InnerText; } if (chanel_item.Name == "img") { XmlNodeList imgList = chanel_item.ChildNodes; foreach (XmlNode img_item in imgList) { if (img_item.Name == "url") { channel.image.URL = img_item.InnerText; } if (img_item.Name == "link") { channel.image.link = img_item.InnerText; } if (img_item.Name == "title") { channel.image.title = img_item.InnerText; } } } if (chanel_item.Name == "item") { XmlNodeList itemsList = chanel_item.ChildNodes; Article article = new Article(); foreach (XmlNode item in itemsList) { if (item.Name == "title") { article.title = item.InnerText; } if (item.Name == "link") { article.link = item.InnerText; } if (item.Name == "description") { article.description = item.InnerText; } if (item.Name == "pubDate") { article.pubDate = item.InnerText; } } channel.addArticle(article); } } channelList.Add(channel); } return channelList; } catch (Exception ex) { MessageBox.Show(ex.Message, " Ошибка загрузки или обработки XML"); return channelList; } }