单个网页存放类 RssResponeObject.cs
using System; using System.Collections.Generic; using System.Text; namespace BaseCommon.Rss { public class RssResponeObject { //<title>400电话申请办理</title> //<link>http://www.my400800.cn</link> //<description>400电话申请办理</description> #region 构造函数 /// <summary> /// 构造函数 /// </summary> /// <param name="strTitle">文章标题</param> /// <param name="strLink">文章链接</param> /// <param name="strDescription">摘要</param> /// <param name="dtPubtime">发布时间</param> /// <param name="strAuthor">作者</param> public RssResponeObject(string strTitle, string strLink, string strDescription, DateTime dtPubtime, string strAuthor) { this.strTitle = strTitle; this.strLink = strLink; this.strDescription = strDescription; this.PubDate = dtPubtime; this.strAuthor = strAuthor; } #endregion #region 标题 /// <summary> /// 标题 /// </summary> private string strTitle = ""; /// <summary> /// 标题 /// </summary> public string Title { get { return strTitle; } set { strTitle = value; } } #endregion #region 摘要 /// <summary> /// 摘要 /// </summary> private string strDescription = ""; /// <summary> /// 摘要 /// </summary> public string Description { get { return strDescription; } set { strDescription = value; } } #endregion #region 链接 /// <summary> /// 链接 /// </summary> private string strLink = ""; /// <summary> /// 链接 /// </summary> public string Link { get { return strLink; } set { strLink = value; } } #endregion #region 作者 /// <summary> /// 作者 /// </summary> private string strAuthor = ""; /// <summary> /// 作者 /// </summary> public string Author { get { return strAuthor; } set { strAuthor = value; } } #endregion #region 发布时间 /// <summary> /// 发布时间 /// </summary> private DateTime strPubDate = DateTime.Now; /// <summary> /// 发布时间 /// </summary> public DateTime PubDate { get { return strPubDate; } set { strPubDate = value; } } #endregion public string GetXml() { string strRet = ""; strRet = string.Concat(" <item>\r\n", " <title><!--[CDATA[", strTitle, "]]></title>\r\n", " <link><![CDATA[", strLink, "]]></link>\r\n", " <author><![CDATA[", strAuthor, "]]></author>\r\n", " <pubDate><![CDATA[", PubDate.GetDateTimeFormats('r')[0].ToString(), "]]></pubDate>\r\n", " <description><![CDATA[", strDescription, "]]--></description>\r\n", " </item>\r\n" ); return strRet; } } }
rss2 生成类 RssResponeWrite.cs
using System; using System.Collections.Generic; using System.Text; namespace BaseCommon.Rss { public class RssResponeWrite { #region rss 2.0 生成对象初始化 构造函数 /// <summary> /// rss 2.0 生成对象初始化 /// </summary> /// <param name="strWebSiteName">网站名称</param> /// <param name="strDomain">网站地址</param> /// <param name="strDescription">网站摘要</param> /// <param name="lsitemList">元素列表</param> public RssResponeWrite(string strWebSiteName, string strDomain, string strDescription, List<RssResponeObject> lsitemList) { this.strWebSiteName = strWebSiteName; this.strDomain = strDomain; this.strDescription = strDescription; this.lsitemList = lsitemList; } #endregion #region 网站名称 /// <summary> /// 网站名称 /// </summary> private string strWebSiteName = ""; /// <summary> /// 网站名称 /// </summary> public string WebSiteName { get { return strWebSiteName; } set { strWebSiteName = value; } } #endregion #region 网站地址 /// <summary> /// 网站地址 /// </summary> private string strDomain = "http://www.my400800.cn"; /// <summary> /// 网站地址 /// </summary> public string Domain { get { return strDomain; } set { strDomain = value; } } #endregion #region 网站摘要 /// <summary> /// 网站摘要 /// </summary> private string strDescription = ""; /// <summary> /// 网站摘要 /// </summary> public string Description { get { return strDescription; } set { strDescription = value; } } #endregion #region 元素列表 /// <summary> /// 元素列表 /// </summary> private List<RssResponeObject> lsitemList = null; /// <summary> /// 元素列表 /// </summary> public List<RssResponeObject> ItemList { get { return lsitemList; } set { lsitemList = value; } } #endregion #region 网站语言 /// <summary> /// 网站语言 /// </summary> private string strLanguage = "zh-cn"; /// <summary> /// 网站语言 /// </summary> public string Language { get { return strLanguage; } set { strLanguage = value; } } #endregion #region 统计系统缓存时间 /// <summary> /// 统计系统缓存时间 /// </summary> private int intTTL = 120; /// <summary> /// 统计系统缓存时间 /// </summary> public int TTL { get { return intTTL; } set { intTTL = value; } } #endregion #region public string GetRss2XML() 取得rss2 xml文件 /// <summary> /// 取得rss2 xml文件 /// </summary> /// <returns></returns> public string GetRss2XML() { string strRet = ""; string strListItemXml = ""; foreach (RssResponeObject robj in lsitemList) { strListItemXml += robj.GetXml(); } strRet = string.Concat("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n", "<rss version=\"2.0\">\r\n", " <channel>\r\n", " <title><!--[CDATA[", strWebSiteName, "]]></title>\r\n", " <description><![CDATA[", strDescription, "]]></description>\r\n", " <link><![CDATA[", strDomain, "]]--></link>\r\n", " <language>", Language, "</language>\r\n", " <ttl>", TTL, "</ttl>\r\n", strListItemXml, "</channel>\r\n", "</rss>" ); return strRet; } #endregion } }
rss2.0生成测试代码
//测试代码 List<RssResponeObject> itemList = new List<RssResponeObject>(); RssResponeObject One = new RssResponeObject("400电话业务简介(电信4008、网通4006、铁通4007)", "http://www.my400800.cn/400YeWuJianJie.aspx", "当前信息详细介绍了电信、网通、铁通400电话的详细业务介绍,希望对您有所帮助。我们是中国目前最专业的400电话及800电话业务在线受理平台,提供铁通、网通400电话、800电话、申请服务,开通快速、资费优惠、靓号任选", DateTime.Now, "www.my400800.cn"); itemList.Add(One); One = new RssResponeObject("中国网通4006电话长市话统一资费标准-400电话800电话申请办理", "http://www.my400800.cn/4006ChangShiHuaTongYiZiFeiBiao.html", "下面就网通4006电话长市话统一资费标准进行了详细的说明,网通4006电话特惠套餐最低800元起,企业办理门槛低,资费低。", DateTime.Now, "www.my400800.cn"); itemList.Add(One); One = new RssResponeObject("400电话资费标准(电信4008、网通4006、铁通4007)", "http://www.my400800.cn/400ZiFeiBiaoZhun.aspx", "当前信息详细介绍了电信、网通、铁通400电话的电话资费标准,希望对您有所帮助。本站提供电信、网通、铁通400免费电话号码申请,800电话全国免费受理。。我们是中国目前最专业的400电话及800电话业务在线受理平台,提供铁通、网通400电话、800电话、申请服务,开通快速、资费优惠、靓号任选", DateTime.Now, "作者"); itemList.Add(One); One = new RssResponeObject("400电话申请流程及概念简单介绍-400电话800电话申请办理", "http://www.my400800.cn/400DianHuaShenQingLiuChengJiGaiNian.html", "400电话申请流程及概念简单介绍-400电话800电话申请办理", DateTime.Now, "400800受理中心"); itemList.Add(One); One = new RssResponeObject("400电话的好处|我们为什么要办理400电话", "http://www.my400800.cn/400DianHuaDeHaoChuWoMenWei.html", "上面我就400电话的好处、400电话适合那些企业办理、400电话给企业带来的好处等一系列相关问题进行了详细的介绍,我相信您从中也就明白了400电话在企业的产品销售、售前咨询、售后服务、提高用户评价度等方面启到了不可忽略的作用。", DateTime.Now, "www.my400800.cn"); itemList.Add(One); One = new RssResponeObject("网通4006主被叫分摊付费业务介绍", "http://www.my400800.cn/WangTong4006ZhuBeiJiaoFenTanFu.html", "400业务只需要对外公布一个唯一的4006号码,对4006号码的呼叫,可根据客户的业务要求接续至不同的号码上.在全国各地固定电话、小灵通、移动电话上均可拨打.,铁通4007电话免费开通,10万400电话号码任您选择,铁通4007业务选号即送大礼!", DateTime.Now, "www.my400800.cn"); itemList.Add(One); RssResponeWrite rss2Write = new RssResponeWrite("全国400电话申请·全国800电话申请·价钱低●信誉好--400800受理中心", "http://www.my400800.cn", "我们是中国目前最专业的400电话及800电话业务在线受理平台,提供铁通400电话、网通400电话、电信400电话、800电话、申请服务,开通快速、资费优惠、靓号任选", itemList); string strRss = rss2Write.GetRss2XML(); Response.Write(strRss);