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

推荐订阅源

博客园 - 叶小钗
云风的 BLOG
云风的 BLOG
G
Google Developers Blog
S
SegmentFault 最新的问题
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
爱范儿
爱范儿
博客园 - 三生石上(FineUI控件)
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
DataBreaches.Net
F
Fortinet All Blogs
TaoSecurity Blog
TaoSecurity Blog
D
Docker
C
Cybersecurity and Infrastructure Security Agency CISA
K
Kaspersky official blog
宝玉的分享
宝玉的分享
腾讯CDC
Google Online Security Blog
Google Online Security Blog
Recorded Future
Recorded Future
T
The Exploit Database - CXSecurity.com
T
The Blog of Author Tim Ferriss
V
V2EX
S
Securelist
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
C
CERT Recently Published Vulnerability Notes
A
Arctic Wolf
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
Y
Y Combinator Blog
P
Proofpoint News Feed
T
Tor Project blog
AWS News Blog
AWS News Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
博客园 - 聂微东
T
Threat Research - Cisco Blogs
B
Blog
Attack and Defense Labs
Attack and Defense Labs
L
Lohrmann on Cybersecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
阮一峰的网络日志
阮一峰的网络日志
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
N
News and Events Feed by Topic
博客园 - 司徒正美
H
Help Net Security
C
Cisco Blogs
C
Check Point Blog
S
Secure Thoughts

博客园 - 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