protected void Page_Load(object sender, EventArgs e) { string url = feedChooser.SelectedValue; if (url.Length == 0) { url = "http://feeds.feedburner.com/PublicoRSS?format=xml"; } XmlReader reader = XmlReader.Create(url); XmlDocument doc = new XmlDocument(); doc.Load(reader); reader.Close(); XmlDataSource_feed.Data = doc.OuterXml; XmlDataSource_feed.DataBind(); XmlDataSource_feed.XPath = "/rss/channel"; XmlDocument docx = XmlDataSource_feed.GetXmlDocument(); XmlElement root = docx.DocumentElement; XmlNodeList nodes = root.SelectNodes(XmlDataSource_feed.XPath); foreach (XmlNode node in nodes) { titleLabel.Text = node.Attributes[0].Value; linkLabel.Text = node.Attributes[1].Value; descriptionLabel.Text = node.Attributes[3].Value; languageLabel.Text = node.Attributes[2].Value; ManagingEditorLabel.Text = node.Attributes[4].Value; WebMasterLabel.Text = node.Attributes[5].Value; LastBuildDateLabel.Text = node.Attributes[6].Value; CategoryLabel.Text = node.Attributes[7].Value; if (node.Attributes[0].Value.Length != 0) { channelImage.Attributes["src"] = node.Attributes[8].Value; } else { channelImage.Attributes["src"] = "http://placehold.it/160x160"; } } XmlNodeList nodes_items = root.SelectNodes("/rss/channel/item"); String innerHtml = ""; foreach (XmlNode node in nodes_items) { String node_html = "<div class=\"col-xs-12 col-md-6 col-lg-4\"><div class=\"well\" style=\"min-height: 300px\"> <div class=\"media\"> <div class=\"media-body\"> <h4 class=\"media-heading\"><a target=\"_blank\" href=\"" + node.Attributes[2].Value + "\">" + node.Attributes[0].Value + "</a></h4> <div class=\"row\"><div class=\"col-md-6\"><small><i class=\"fa fa-tag\"></i> " + node.Attributes[3].Value + "</small></div><div class=\"col-md-6\" style=\"text-align: right\"><small><i class=\"fa fa-calendar - check - o\"></i> " + node.Attributes[4].Value + "</small></div></div><p>" + node.Attributes[1].Value + "</p></div></div></div></div>"; innerHtml += node_html; } news.InnerHtml = innerHtml; }
protected void formFeeds_ItemUpdating(object sender, FormViewUpdateEventArgs e) { XmlDocument docx = XmlDataSource_feed.GetXmlDocument(); XmlElement feed = docx.SelectSingleNode("feeds/feed[@name='" + e.OldValues[0].ToString() + "'][@url='" + e.OldValues[1].ToString() + "']") as XmlElement; feed.Attributes["url"].Value = e.NewValues["url"].ToString(); XmlDataSource_feed.Save(); XmlDataSource_feed.DataBind(); e.Cancel = true; formFeeds.ChangeMode(FormViewMode.ReadOnly); }
protected void formFeeds_ItemInserting(object sender, FormViewInsertEventArgs e) { XmlDocument docx = XmlDataSource_feed.GetXmlDocument(); XmlElement feeds = docx.SelectSingleNode("feeds") as XmlElement; XmlElement feed = docx.CreateElement("feed"); XmlAttribute name = docx.CreateAttribute("name"); XmlAttribute url = docx.CreateAttribute("url"); name.InnerText = ((TextBox)formFeeds.Row.Cells[0].FindControl("nameInsert")).Text; url.InnerText = ((TextBox)formFeeds.Row.Cells[0].FindControl("urlInsert")).Text; feeds.AppendChild(feed); feed.Attributes.Append(name); feed.Attributes.Append(url); XmlDataSource_feed.Save(); XmlDataSource_feed.DataBind(); formFeeds.DataBind(); formFeeds.ChangeMode(FormViewMode.ReadOnly); e.Cancel = true; }
protected void Page_Load(object sender, EventArgs e) { string url = feedChooser.SelectedValue; if (url.Length == 0) { url = "http://feeds.feedburner.com/PublicoRSS?format=xml"; } XmlReader xreader = XmlReader.Create(url); XmlDocument xdoc = new XmlDocument(); xdoc.Load(xreader); xreader.Close(); XmlDataSource_feed.Data = xdoc.OuterXml; XmlDataSource_feed.DataBind(); XmlDataSource_feed.XPath = "/rss/channel"; XmlDocument docx = XmlDataSource_feed.GetXmlDocument(); XmlElement root = docx.DocumentElement; XmlNodeList nodes = root.SelectNodes(XmlDataSource_feed.XPath); foreach (XmlNode node in nodes) { if (node.Attributes[0].Value.Length != 0) { titleLabel.Text = node.Attributes[0].Value; } else { title_.Visible = false; } if (node.Attributes[1].Value.Length != 0) { linkLabel.Text = node.Attributes[1].Value; } else { link_.Visible = false; } if (node.Attributes[3].Value.Length != 0) { descriptionLabel.Text = node.Attributes[3].Value; } else { description_.Visible = false; } if (node.Attributes[2].Value.Length != 0) { languageLabel.Text = node.Attributes[2].Value; } else { language_.Visible = false; } if (node.Attributes[4].Value.Length != 0) { ManagingEditorLabel.Text = node.Attributes[4].Value; } else { managingeditor_.Visible = false; } if (node.Attributes[5].Value.Length != 0) { WebMasterLabel.Text = node.Attributes[5].Value; } else { webmaster_.Visible = false; } if (node.Attributes[6].Value.Length != 0) { LastBuildDateLabel.Text = node.Attributes[6].Value; } else { lastbuild_.Visible = false; } if (node.Attributes[7].Value.Length != 0) { CategoryLabel.Text = node.Attributes[7].Value; } else { category_.Visible = false; } if (node.Attributes[8].Value.Length != 0) { channelImage.Attributes["src"] = node.Attributes[8].Value; } else { channelImage.Attributes["src"] = "http://vignette3.wikia.nocookie.net/max-steel-reboot/images/7/72/No_Image_Available.gif/revision/latest?cb=20130902173013"; } } XmlNodeList node_items = root.SelectNodes("/rss/channel/item"); String innerHtml = ""; feed_info.Visible = true; foreach (XmlNode node in node_items) { String node_html = "<div class=\"col-xs-12 col-md-6 col-lg-4\"><div class=\"well\" style=\"min-height: 300px\"> <div class=\"media\"> <div class=\"media-body\"> <h4 class=\"media-heading\"><a target=\"_blank\" href=\"" + node.Attributes[2].Value + "\">" + node.Attributes[0].Value + "</a></h4> <div class=\"row\"><div class=\"col-md-6\"><small><i class=\"fa fa-tag\"></i> " + node.Attributes[3].Value + "</small></div><div class=\"col-md-6\" style=\"text-align: right\"><small><i class=\"fa fa-calendar - check - o\"></i> " + node.Attributes[4].Value + "</small></div></div><p>" + node.Attributes[1].Value + "</p></div></div></div></div>"; innerHtml += node_html; } counter_news.Text = node_items.Count.ToString(); news.InnerHtml = innerHtml; XmlDocument doc_1 = new XmlDocument(); doc_1.Load(@"C:\Users\hugof\Documents\GitHub\EDC-Trabalho-Final\EDC-Trabalho-Final\App_Data\FeedsList.xml"); XmlNodeList elemList = doc_1.GetElementsByTagName("feed"); String[] feeds = new String[elemList.Count]; HashSet <String> categories = new HashSet <String>(); categories.Add("All"); for (int i = 0; i < elemList.Count; i++) { feeds[i] = elemList[i].Attributes["url"].Value; } for (int i = 0; i < feeds.Length; i++) { XmlReader reader_1 = null; try { reader_1 = XmlReader.Create(feeds[i]); } catch { continue; } XmlDocument doc_aux = new XmlDocument(); doc_aux.Load(reader_1); xreader.Close(); //XmlNodeList aux = doc_aux.SelectNodes("/rss/channel/item//*[contains(.," + findString+")]"); XmlNodeList aux = doc_aux.SelectNodes("/rss/channel/item/category"); foreach (XmlNode cat in aux) { if (!categories.Contains(cat.InnerText) && cat.InnerText != "") { categories.Add(cat.InnerText); //teste.Value += ("\n" + cat.InnerText); } } } if (!IsPostBack || repopulate) { DD_Category.DataSource = categories; DD_Category.DataBind(); repopulate = false; } }