惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Microsoft Security Blog
Microsoft Security Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
V
Visual Studio Blog
宝玉的分享
宝玉的分享
IT之家
IT之家
人人都是产品经理
人人都是产品经理
T
The Blog of Author Tim Ferriss
I
InfoQ
B
Blog RSS Feed
T
Threatpost
博客园_首页
M
MIT News - Artificial intelligence
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Know Your Adversary
Know Your Adversary
U
Unit 42
Engineering at Meta
Engineering at Meta
C
Cyber Attacks, Cyber Crime and Cyber Security
月光博客
月光博客
Scott Helme
Scott Helme
T
Tor Project blog
有赞技术团队
有赞技术团队
AWS News Blog
AWS News Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI
S
Schneier on Security
Vercel News
Vercel News
博客园 - Franky
C
Cybersecurity and Infrastructure Security Agency CISA
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
L
LangChain Blog
爱范儿
爱范儿
Google DeepMind News
Google DeepMind News
The GitHub Blog
The GitHub Blog
雷峰网
雷峰网
Latest news
Latest news
C
CXSECURITY Database RSS Feed - CXSecurity.com
Hugging Face - Blog
Hugging Face - Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
G
GRAHAM CLULEY
S
Security Affairs
A
About on SuperTechFans
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
大猫的无限游戏
大猫的无限游戏
W
WeLiveSecurity
Cisco Talos Blog
Cisco Talos Blog
罗磊的独立博客

博客园 - miao~

C# 截取1位小数 ASP.NET 获取MSN联系人列表 扩展老赵的 直接通过User Control生成HTML 分页功能 小技巧在Repeater控件中找到对应模板内的控件 大型互联网网站架构心得之一:分 UML 序列图 sql存储过程教程 Create an ASP.NET AJAX Style Folder Explorer BS程序代码与安全与基本攻击/防御模式 利用 .NET 3.5 的 Syndication 相关类生成 RSS RSS2.0规范 使用linq to xml 快速创建自己的Rss 代码设计简单规范 VS.PHP 在Visual Studio 下的 PHP 开发 IDE 工具 窥探jQuery——面向JavaScript程序员 开发一个适合Ajax+JSON+jQuery环境使用的多功能页码栏——jPagerBar-1.1.1 最实用的12条css技巧 不错的下拉列表.HTML控件和服务器控件都可以使用 两个粒度看Asp.net生命周期
利用 .NET 3.5 的 Syndication 相关类读取 RSS Feeds
miao~ · 2008-05-26 · via 博客园 - miao~

在 .NET 3.5 类库中新增了 Syndication 相关的一些类,可用来读取或提供 RSS Feeds.
首先,需要添加对 System.ServiceModel.Web 这个程序集的引用。
其中包含了 System.ServiceModel.Syndication 名称空间。
一些主要的类如下:

  • SyndicationFeed
  • SyndicationItem
  • SyndicationContent
  • SyndicationLink
  • SyndicationPerson
  • SyndicationCategory

    这些分别代表 RSS Feed 中相关的 xml 元素。他们是独立于具体 RSS 格式的。

    而要区分格式,则有下列一些 Formatter 类:

    • Rss20FeedFormatter
    • Rss20ItemFormatter
    • Atom10FeedFormatter
    • Atom10ItemFormatter

    分别对应于 RSS 2.0 和 Atom 1.0 两种标准。

    下面是一个简单的 asp.net 例子,用这些 API 读取博客园的 Feed 进行显示。

    Default.aspx

    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        
    <title>Untitled Page</title>
    </head>
    <body>
        
    <form id="form1" runat="server">
        
    <div>
            
    <asp:Label ID="lblTitle" runat="server" />
            
    <asp:Repeater ID="repeater1" runat="server">
                
    <ItemTemplate>
                    
    <dl>
                        
    <dt>
                            
    <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("Title.Text") %>'
                                Font-Bold="true"
                                NavigateUrl='
    <%Eval("Links[0].Uri.AbsoluteUri"%>' />                        
                        
    </dt>
                        
    <dd><%Eval("Summary.Text"%></dd>
                        
    <dd><%Eval("PublishDate.DateTime""发表于:{0}"%></dd>
                    
    </dl>
                
    </ItemTemplate>
            
    </asp:Repeater>
            
    <hr /><asp:Label ID="lblCopyright" runat="server" />
        
    </div>
        
    </form>
    </body>
    </html>

    Default.aspx.cs

    using System;
    using System.ServiceModel.Syndication;
    using System.Xml;public partial class _Default : System.Web.UI.Page 
    {
        
    protected void Page_Load(object sender, EventArgs e)
        {
            
    if (!IsPostBack)
            {
                var feed 
    = new Rss20FeedFormatter();
                
    using (var xreader = XmlReader.Create("http://www.cnblogs.com/rss"))
                {
                    feed.ReadFrom(xreader);
                }
                lblTitle.Text 
    = feed.Feed.Title.Text;
                
    if (feed.Feed.Copyright != null)
                {
                    lblCopyright.Text 
    = feed.Feed.Copyright.Text;
                }
                repeater1.DataSource 
    = feed.Feed.Items;
                repeater1.DataBind();
            }
        }
    }

  • 转载:http://www.cnblogs.com/RChen/archive/2008/04/22/1165178.html