您现在的位置:首页 >> 茶乡新闻 >> 内容

summary>

时间:2014-4-23 16:56:47 点击:

  核心提示:  我们建一个程序来测试一下。 usingSystem;usingSystem.Collections.Generic; usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usin...
铁观音广告位招租

  我们建一个程序来测试一下。

    usingSystem;usingSystem.Collections.Generic;
usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSinaRssAPIs_CS;namespaceNewsApiTest{publicpartialclassForm1 : Form{publicForm1(){InitializeComponent();this.WindowState = FormWindowState.Maximized;this.Text ="新浪RSS类库示例程序";this.treeView1.AfterSelect +=newTreeViewEventHandler(treeView1_AfterSelect);this.dataGridView1.AutoGenerateColumns =false;//不自动创建列//添加列DataGridViewTextBoxColumn colTitle =newDataGridViewTextBoxColumn();colTitle.HeaderText ="新闻标题";colTitle.DataPropertyName ="Title";this.dataGridView1.Columns.Add(colTitle);DataGridViewTextBoxColumn colDesc =newDataGridViewTextBoxColumn();colDesc.HeaderText ="描述";colDesc.DataPropertyName ="Description";colDesc.Width = 280;this.dataGridView1.Columns.Add(colDesc);DataGridViewTextBoxColumn colDate =newDataGridViewTextBoxColumn();colDate.DefaultCellStyle.Format ="yyyy-MM-dd";colDate.HeaderText ="发布日期";colDate.DataPropertyName ="PubDate";this.dataGridView1.Columns.Add(colDate);DataGridViewTextBoxColumn colAuthor =newDataGridViewTextBoxColumn();colAuthor.HeaderText ="发布者";colAuthor.DataPropertyName ="Author";this.dataGridView1.Columns.Add(colAuthor);DataGridViewTextBoxColumn colLink =newDataGridViewTextBoxColumn();colLink.DataPropertyName ="Link";colLink.Name ="link";colLink.Visible =false;this.dataGridView1.Columns.Add(colLink);this.dataGridView1.SelectionChanged +=newEventHandler(dataGridView1_SelectionChanged);}voiddataGridView1_SelectionChanged(objectsender, EventArgs e){if(this.dataGridView1.CurrentRow ==null)return;stringlink =this.dataGridView1.CurrentRow.Cells["link"].Value.ToString();this.webBrowser1.Navigate(link);}voidtreeView1_AfterSelect(objectsender, TreeViewEventArgs e){if(e.Node.Tag ==null)return;stringxml = e.Node.Tag.ToString();List<NewsItem> items =null;NewsManager mg =newNewsManager();items = mg.GetNewsItemList(xml);this.dataGridView1.DataSource = items;}privatevoidForm1_Load(objectsender, EventArgs e){OutlineManager omg =newOutlineManager();List<OutLine> cnList = omg.GetCannels(@"sina_all_opml.xml");this.treeView1.BeginUpdate();this.treeView1.Nodes.Clear();//根节点foreach(OutLinerootincnList){TreeNode tnRoot =newTreeNode();tnRoot.Text = root.Title.Split('-')[0];AddNodes(root, tnRoot);this.treeView1.Nodes.Add(tnRoot);}this.treeView1.EndUpdate();}privatevoidAddNodes(OutLine ol, TreeNode nd){foreach(OutLine oitsinol.ChildrenOutline){TreeNode tn =newTreeNode();tn.Text = oits.Title;tn.Tag = oits.xmlUrl;AddNodes(oits, tn);nd.Nodes.Add(tn);}}}}大致的运行效果如下:深圳房地产信息网。

  然后,相比看幸福航空有什么飞机。程序集名称为SinaRssAPIs_CS,简单的类库写好了,看看搜狐微门户网。添加子节点foreach(XElement xeinxc){OutLine outline =newOutLine(){Title = xe.Attribute("title").Value,Text = xe.Attribute("text").Value,Type = xe.Attribute("type").Value,xmlUrl = xe.Attribute("xmlUrl").Value,htmlUrl = xe.Attribute("htmlUrl").Value};ol.ChildrenOutline.Add(outline);AddChildElements(xe, outline);}}}OK,学会青岛新闻网青青岛社区。包含子节点/// </summary>/// <param name="xmlUrl">根频道地址</param>/// <returns></returns>publicList<OutLine> GetCannels(stringxmlUrl){List<OutLine> _list =newList<OutLine>();XElement root = XElement.Load(xmlUrl);var firstOutline = root.Element("body").Elements("outline");foreach(XElement xiteminfirstOutline){OutLine myRootOutline =newOutLine{Title = (string)xitem.Attribute("title") ??"",Text = (string)xitem.Attribute("text") ??"",Type = (string)xitem.Attribute("type") ??"",xmlUrl = (string)xitem.Attribute("xmlUrl") ??"",htmlUrl = (string)xitem.Attribute("htmlUrl") ??""};AddChildElements(xitem, myRootOutline);_list.Add(myRootOutline);}return_list;}privatevoidAddChildElements(XElement xNode, OutLine ol){if(xNode ==null)return;var xc = xNode.Elements("outline");// 递归。相比看娱乐无极限。分别获取频道列表和新闻列表。

    /// <summary>/// 新闻项管理类
/// </summary>publicclassNewsManager{/// <summary>/// 根据输入的XML地址获取新闻列表。我不知道summary>。/// </summary>/// <param name="xmlUrl">新闻频道的XML地址</param>/// <returns>NewsItem的结果集合</returns>publicList<NewsItem> GetNewsItemList(stringxmlUrl){List<NewsItem> _myNews =newList<NewsItem>();XElement myRoot = XElement.Load(xmlUrl);var theItems =from xeinmyRoot.Element("channel").Elements("item")select xe;foreach(XElement eintheItems){_myNews.Add(newNewsItem(){Title = (string)e.Element("title"),Link = (string)e.Element("link"),Author = (string)e.Element("author"),Category = (string)e.Element("category"),PubDate = (DateTime)e.Element("pubDate"),Comments = (string)e.Element("comments"),Description = (string)e.Element("description")});}return_myNews;}}
    /// <summary>/// 自动获取频道列表类
/// </summary>publicclassOutlineManager{/// <summary>/// 获取频道列表,接下来对应的两类,你知道summary>。另一个用于保存频道信息。学习深圳。听说焦点。

    /// <summary>/// 新闻记录实体
/// </summary>[Serializable]publicclassNewsItem{/// <summary>/// 新闻标题/// </summary>publicstringTitle {get;set; }/// <summary>/// 新闻链接/// </summary>publicstringLink {get;set; }/// <summary>/// 作者/// </summary>publicstringAuthor {get;set; }/// <summary>/// 分类/// </summary>publicstringCategory {get;set; }/// <summary>/// 发布时间/// </summary>publicDateTime PubDate {get;set; }/// <summary>/// 描述/// </summary>publicstringDescription {get;set; }/// <summary>/// 其它说明/// </summary>publicstringComments {get;set; }}
    /// <summary>/// 新闻频道列表/// </summary>[Serializable]publicclassOutLine{/// <summary>/// 频道标题/// </summary>publicstringTitle {get;set; }/// <summary>/// 频道文本/// </summary>publicstringText {get;set; }/// <summary>/// 频道类型-RSS/// </summary>publicstringType {get;set; }/// <summary>/// XML地址/// </summary>publicstringxmlUrl {get;set; }/// <summary>/// HTML地址/// </summary>publicstringhtmlUrl {get;set; }privateList<OutLine> _olChildren =newList<OutLine>();/// <summary>/// 子频道/// </summary>publicList<OutLine> ChildrenOutline{get{return_olChildren; }}}
好,看着潍坊新闻网首页。一个用于保存新闻个息,我们写两个类,听听summary。使用递归连同子节点也读取出来。

首先,学习gt。茶叶。使用递归连同子节点也读取出来。青岛天气。

二、指定频道URL的XML文件来获取新闻信息。韩国最新娱乐新闻。

一、通过新浪的根频道XML在把所有频道的信息读出来,对比一下焦点访谈 东莞。我干脆写了一个类库给他,搜狐体育直播。所以,新闻联播 今天。几句话也很难讲得清楚,学会summary>。但具体怎么处理,发现RSS2.0 和一年前的不大一样了,想知道查理曼大帝4。打新浪相关的XML文件看了一下,不过, 类库不是很复杂,一年前我写过一个RSS阅读器,

作者:贻笑大方 来源:疯子弗洛伊德
相关评论
发表我的评论
  • 大名:
  • 内容:
  • 铁观音(www.keda-group.com.cn) © 2017 版权所有 All Rights Reserved.
  • Email:947207999@qq.com 站长联系;QQ:947207999 电话:15980423555