IP得到天气预报(4)———制作自己的RSS订阅

  • 前面的几个Session中,目的就是通过IP的不同,得到不同的数据。从而到雅虎上爬取天气情况。具体的已经发布到服务器了。大家可以自己测试。
  • 既然自己已经有了自己的天气预报了。那么也可以有自己的RSS了。我采用了RSSToolkit这个开源的控件,简单易用。
  • 首先找个地方下载这个DLL,添加引用。详细的使用说明大家可以参考官方的说明。
  • 为了得到相应的XML。简单的设计一个模式。
  •   <?xml version="1.0" encoding="utf-16" ?> 
    -
    <rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    -
    <channel>
    -
    <item>
    <author>alex</author>
    <description>……数据库维护中……</description>
    <guid />
    <link>http://www.zhumx.com/alex/weather.aspx</link>
    <pubDate>2008-11-19 0:00:00</pubDate>
    <pubDateParsed>2008-11-19T00:00:00</pubDateParsed>
    <title>今日天气预报</title>
    <source />
    </item>
    </channel>
    </rss>
  • 有几个必要的信息是必须填写的。代码如下。
     
  • using System;
    using System.Collections;
    using System.Data;
    using System.Web;
    using RssToolkit.Rss;
    using RssToolkit.Web;
    using System.IO;
    using System.Text;
    using System.Collections.Generic;
    namespace weather
    {
    public partial class WeatherRSS : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    RssDocument aDoc
    = new RssDocument();
    aDoc.Channel
    = new RssChannel();
    aDoc.Channel.Items
    = new List<RssItem>();
    RssItem aItem
    =new RssItem ();
    aItem.Guid
    =new RssGuid ();
    aItem.Author
    ="alex";
    aItem.Description
    ="……数据库维护中……";
    aItem.Link
    = "http://www.zhumx.com/alex/weather.aspx";
    aItem.PubDate
    =DateTime.Today .ToString ();
    aItem.Title
    ="今日天气预报";
    aItem.Source
    =new RssSource();

    aDoc.Channel.Items.Add(aItem);
    string aText=aDoc.ToXml(DocumentType.Rss);
    this.Response .ContentType ="text/xml";
    StreamWriter aWriter
    = new StreamWriter(this.Response.OutputStream, Encoding.Unicode);
    aWriter.Write(aText);
    aWriter.Flush();
    }
    }
    }
  • 总的来说比较简单,没有什么太多好说明的。那么到此为止,一个任何IP国内的,都能到到自己的天气预报基本上就完成了。
  • 简单加个链接目录,有兴趣的可以一起研究下:)
  • IP得到天气预报(1)———数据分析存储
  • IP得到天气预报(2)———IP运算和数据处理
  • IP得到天气预报(3)———XML中CDATA的提取
  • IP得到天气预报(4)———制作自己的RSS订阅
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值