Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Xml;
- using System.Data;
- namespace EBiznes1
- {
- public partial class News : System.Web.UI.Page
- {
- XmlTextReader XmlTextRssReader;
- XmlDocument XmlDocumentRss;
- XmlNode XmlNodeRss;
- XmlNode nodeChannel;
- XmlNode nodeItem;
- DataTable table = new DataTable();
- protected void Page_Load(object sender, EventArgs e)
- {
- DataColumn col = table.Columns.Add("Заглавие на новина");
- DataColumn col1 = table.Columns.Add("Линк");
- XmlTextRssReader = new XmlTextReader("http://rss.cnn.com/rss/edition_europe.rss");
- XmlDocumentRss = new XmlDocument();
- // load the xml content into object XmlDocument
- XmlDocumentRss.Load(XmlTextRssReader);
- // for loop to check the <rss> tag
- for (int i = 0; i < XmlDocumentRss.ChildNodes.Count; i++)
- {
- if (XmlDocumentRss.ChildNodes[i].Name == "rss")
- // if there is a <rss> tag, it's data is loaded
- XmlNodeRss = XmlDocumentRss.ChildNodes[i];
- }
- // check if there are tags in RSS do the following commands
- if (XmlNodeRss.ChildNodes.Count != 0)
- { // for loop to check the <channel> tag
- for (int i = 0; i < XmlNodeRss.ChildNodes.Count; i++)
- {
- if (XmlNodeRss.ChildNodes[i].Name == "channel")
- // if there is a <channel> tag
- nodeChannel = XmlNodeRss.ChildNodes[i];
- }
- // load channel's data in labels
- lblTitle.Text = "Title: " + nodeChannel["title"].InnerText;
- lblLanguage.Text = "Language: " + nodeChannel["language"].InnerText;
- lblLink.Text = "Link: " + nodeChannel["link"].InnerText;
- lblDescription.Text = "Description: " + nodeChannel["description"].InnerText;
- // for loop to fill in the titles and links to the news in GridView
- for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)
- {
- if (nodeChannel.ChildNodes[i].Name == "item") // only check the news
- {
- nodeItem = nodeChannel.ChildNodes[i];
- // in the GridView: create a row that gets info about the news (title and link) from the tags
- DataRow row = table.NewRow();
- row[0] = nodeItem["title"].InnerText;
- row[1] = nodeItem["link"].InnerText;
- table.Rows.Add(row);
- table.AcceptChanges();
- GrViewNews.DataSource = table;
- GrViewNews.DataBind();
- //HyperLink hl = (HyperLink)GrViewNews.FindControl("HyperLink1");
- //hl.NavigateUrl = nodeItem["link"].InnerText;
- foreach (GridViewRow gvr in GrViewNews.Rows)
- {
- if (gvr.RowType == DataControlRowType.DataRow)
- {
- HyperLink myHyperLink = gvr.FindControl("HyperLink1") as HyperLink;
- myHyperLink.NavigateUrl = nodeItem["link"].InnerText;
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement