点击回首页
我的浏览记录 | | 帮助?
当前位置:

源码截图

源码目录树

当前路径:LetSearch/App-Code/Rss.cs     using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Text;
using System.IO;
using System.Xml;

/// <summary>
/// Rss 的摘要说明
/// </summary>
public class Rss
{
	public Rss()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}

    public static string GetRssNews(string url,int count)
    {
        StringBuilder sb = new StringBuilder();
        WebRequest myRequest = WebRequest.Create(url);
        WebResponse myResponse = myRequest.GetResponse();

        Stream rssStream = myResponse.GetResponseStream();
        XmlDocument rssDoc = new System.Xml.XmlDocument();
        rssDoc.Load(rssStream);

        XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item");

        string title = "";
        string link = "";
        string pubDate = "";
        sb.Append("<AllNews>");
        if (rssItems.Count > 0)
        {
            int num = 0;
            if (rssItems.Count >= count)
            {
                num = count;
            }
            else
            {
                num = rssItems.Count;
            }
            sb.Append("<newsCount>" + num.ToString() + "</newsCount>");
            for (int i = 0; i < num; i++)
            {
                XmlNode rssDetail = rssItems.Item(i).SelectSingleNode("title");
                if (rssDetail != null)
                {
                    title =InsApp.word.CreateCode.CutStr(rssDetail.InnerText.ToString(),44);
                }
                else
                {
                    title = "【点击查看新闻】";
                }

                rssDetail = rssItems.Item(i).SelectSingleNode("link");
                if (rssDetail != null)
                {
                    link = rssDetail.InnerText;
                }
                else
                {
                    link = "";
                }

                rssDetail = rssItems.Item(i).SelectSingleNode("pubDate");
                if (rssDetail != null)
                {
                    pubDate = rssDetail.InnerText;
                }
                else
                {
                    pubDate = "";
                }
                sb.Append("<News>");
                sb.Append("<title>");
                sb.Append(title);
                sb.Append("</title>");
                sb.Append("<link>");
                sb.Append(link);
                sb.Append("</link>");
                sb.Append("<pubDate>");
                sb.Append(pubDate);
                sb.Append("</pubDate>");
                sb.Append("</News>");
            }
        }
        else
        {
            sb.Append("<newsCount>0</newsCount>");
        }
        sb.Append("</AllNews>");

        return sb.ToString();
    }
}
关于我们 | 顾问团队 | 发展历程 | 联系我们 | 源码上传
联系电话(Tel):4008-010-151(免长途) 企业QQ:4000410510
地址:北京市海淀区中关村鼎好大厦A座二层 邮编:100080
Room A-801,Dinghao Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2015. 京ICP备09089570号 | 京公网安备11010702000869号
在线客服
分享该页面
关闭侧边栏