public void LoadRss() { //string channeltitle = "网易头条"; //string channellink ="http://news.163.com/"; //string rsspath = "http://news.163.com/special/00011K6L/rss_newstop.xml";//RSS地址 string[] rsspath ={ "http://news.163.com/special/00011K6L/rss_newstop.xml", "http://www.xinhuanet.com/politics/news_politics.xml", "http://news.baidu.com/n?cmd=1&class=civilnews&tn=rss&sub=0", "http://www.shanghai.gov.cn/shanghai/node27041/node27044/index.xml", "http://news.online.sh.cn/news/gb/special/news.xml", "http://rich.online.sh.cn/rich/gb/special/rich.xml"};//RSS地址 string[] channeltitle ={"网易头条", "新华时政", "百度国内焦点", "中国上海", "上海新闻热线", "上海财经热线"}; string[] channellink ={"http://news.163.com/", "http://www.xinhuanet.com/politics/xw.htm", "http://news.baidu.com", "http://www.shanghai.gov.cn/shanghai/node2314/index.html", "http://news.online.sh.cn/news/gb/node/news_default.htm", "http://rich.online.sh.cn/rich/gb/node/node_54714.htm"}; for (int cid = 0; cid < 6; cid++) { XmlDocument doc = new XmlDocument();//创建文档对象 try { doc.Load(rsspath[cid]);//加载XML 包括HTTP:// 和本地 } catch (Exception) { //异常处理 } //初始化Rss XmlNodeList list = doc.GetElementsByTagName("item"); //获得项 XmlNode node = list.Item(1);// NewsItem item = new NewsItem(); item = getItem((XmlElement)node); item.ChannelLink = channellink[cid]; item.ChannelTitle = channeltitle[cid]; //加入list items.Add(item); } //添加绑定操作 this.Rsslist.ItemsSource = items; }
private NewsItem getItem(XmlElement ele) { NewsItem item = new NewsItem(); item.Title = ele.GetElementsByTagName("title")[0].InnerText;//获得标题 item.Link = ele.GetElementsByTagName("link")[0].InnerText;//获得联接 string des = ele.GetElementsByTagName("description")[0].InnerText;//获得简介 if (des.Length > 80) { des = des.Substring(0, 80) + "……"; } item.Description = des; //item.PubDate = ele.GetElementsByTagName("pubDate")[0].InnerText;//获得发布日期 return item; }
public void LoadRss() { string[] rsspath ={ "http://news.tongji.edu.cn/rss.php?classid=6", //"http://www.xinhuanet.com/politics/news_politics.xml", "http://news.tongji.edu.cn/rss.php?classid=7", "http://news.tongji.edu.cn/rss.php?classid=8" ,"http://news.tongji.edu.cn/rss.php?classid=10" };//RSS地址 string[] channeltitle ={"同济大学综合新闻", //"新华时政", "同济大学教学新闻", "同济大学科研新闻" ,"同济大学外事新闻" }; string[] channellink ={"http://news.tongji.edu.cn/classid-176.html", //"http://www.xinhuanet.com/politics/xw.htm", "http://news.tongji.edu.cn/classid-176.html", "http://news.tongji.edu.cn/classid-176.html" ,"http://news.tongji.edu.cn/classid-176.html" }; string[] logopath = { "/Images/logo_tongji.jpg", //"/Images/新华1.jpg", "/Images/logo_tongji.jpg", "/Images/logo_tongji.jpg" ,"/Images/logo_tongji.jpg" }; for (int cid = 0; cid < 4; cid++) { XmlDocument doc = new XmlDocument();//创建文档对象 try { doc.Load(rsspath[cid]);//加载XML 包括HTTP:// 和本地 } catch (Exception) { //异常处理 } //初始化Rss XmlNodeList list = doc.GetElementsByTagName("item"); //获得项 XmlNode node = list.Item(0);// NewsItem item = new NewsItem(); item = getItem((XmlElement)node); item.ChannelLink = channellink[cid]; item.ChannelTitle = channeltitle[cid]; item.LogoPath = logopath[cid]; //加入list items.Add(item); } //添加绑定操作 this.Rsslistleft.ItemsSource = items; this.Rsslistleft1.ItemsSource = items; }