还记得以前吗?以前要做页面上写个小组件,调用指定(RSS输出地址的)的内容。最好的办法就是通过XSLT+XML来输出字符 串。让我们还是花了一分钟的时候回忆一下以前的做法吧 曾经的做法: Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) Dim xArgList As XsltArgumentList = New XsltArgumentList End SubXSLT转换文件 <?xml version=”1.0″ encoding=”gb2312″?> <msxsl:script language=”VB” implements-prefix=”resuls”> public function strDate(byval s as string)as string <xsl:template match=”channel”> http://download.pchome.net/allimage/p1.gif”/></td 而现在。根据MS的想法。一切只要拖拖控件就能完成我们的所要功能(我一向不喜欢这样,还是自己DIY好)。所以。下面介绍这款小工具:ASP.NET RSS Toolkit 创建新的页面 为datalist控件创建新的数据源 选择rssDataSource 输入RSS地址(我这里以http://rss.msnbc.msn.com/id/3032091/device/rss/rss.xml) 根据RSS输出的格式,进行绑定 OK。现在可以浏览一下效果 晚上出去吃晚饭的时候。走出外面,感觉到夏天的来到。呵。我喜欢夏天的这种感觉。带上好的心情,出去走走。也是一种很好的享受。最后。推荐一首歌:夏天的味道。
Dim CacheKey As String = Url & “-” & Sort
Dim objCache As System.Web.Caching.Cache = HttpRuntime.Cache
If objCache.Item(CacheKey) Is Nothing Then
Dim xpDocument As XPathDocument = New XPathDocument(Url, XmlSpace.Preserve)
Dim XTran As XslTransform = New XslTransform
XTran.Load(Web.HttpRuntime.AppDomainAppPath & “TransForm.xsl”) TransForm.xsl
Dim sw As StringWriter = New StringWriter
xArgList.AddParam(“Sort”, “”, Sort)
xArgList.AddParam(“strlength”, “”, strLength)
XTran.Transform(xpDocument, xArgList, sw)
objCache.Insert(CacheKey, sw, Nothing, DateTime.Now.AddMinutes(15), TimeSpan.Zero)
End If
MyBase.Text = CType(objCache.Item(CacheKey), StringWriter).ToString
<xsl:stylesheet
version=”1.0″
xmlns:xsl=”http://www.w3.org/1999/XSL/Transform“
xmlns=”http://www.w3.org/TR/REC-html40”
xmlns:msxsl=”urn:schemas-microsoft-com:xslt”
xmlns:dc=”http://purl.org/dc/elements/1.1/“
xmlns:slash=”http://purl.org/rss/1.0/modules/slash/“
xmlns:sy=”http://purl.org/rss/1.0/modules/syndication/“
xmlns:resuls=”urn:StrLength”>
<xsl:param name=”Sort” select=”10″></xsl:param>
<xsl:param name=”strlength” select=”15″></xsl:param>
<xsl:template match=”//rss”>
<xsl:apply-templates select=”channel” />
</xsl:template>
<![CDATA[
Function GetSubString(byval origStr As String, byval endIndex As Integer) As String
Dim bytes As Byte() = System.Text.Encoding.GetEncoding(“gb2312”).GetBytes(origStr)
If endIndex >= bytes.Length Then
Return origStr
End If
Dim subBytes(endIndex) As Byte
Array.Copy(bytes, 0, subBytes, 0, endIndex)
Return System.Text.Encoding.GetEncoding(“gb2312”).GetString(subBytes) + “”
End Function GetSubString
return CDate(s).Day.ToString & “日”
end function
]]>
</msxsl:script>
<table width=”300″ border=”0″ cellspacing=”0″ cellpadding=”0″>
<xsl:for-each select=”item”>
<xsl:if test=”position() <=$Sort”>
<tr>
<td width=”21″><img src=”http://www.knowsky.com/
<td><a href=”{link}”><xsl:value-of select=”resuls:GetSubString(title,$strlength)”/></a> <xsl:value-of select=”resuls:strDate(dc:date)”/></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
RSS TOOLKIT主要是从服务器上装载RSS输出(XML格式输出),生成数据集,然后填充到DATALIST控件当中。另外它支持数据缓存的功能
目前最新版本:1.0.0.1
新的特性:
• Added MaxItems property to RssDataSource to limit the number of items returned.
• Added automatic generation of <link> tags from RssHyperLink control, to light up the RSS
toolbar icon in IE7. For more information please see http://blogs.msdn.com/rssteam/articles/PublishersGuide.aspx
• Added protected Context property (of type HttpContext) to RssHttpHandlerBase class, to allow access to the
HTTP request while generating a feed.
• Added generation of LoadChannel(string url) method in RssCodeGenerator so that one strongly typed
channel class can be used to consume different channels.
• Fixed problem expanding app relative (~/…) links containing query string when generating RSS feeds.
下载地址:点击下载
详细说明:http://weblogs.asp.net/scottgu/archive/2006/02/22/438738.aspx
<%@ Register Assembly=“RssToolkit“ Namespace=“RssToolkit“ TagPrefix=“RssToolkit“ %>
<html>
<head runat=”server”>
<title>ScottGu Feed</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<h2>ScottGu Blog Feed</h2>
<asp:DataList ID=”DataList1″ runat=”server” CellPadding=”4″ DataSourceID=”RssDataSource1″ ForeColor=”#333333″>
<ItemTemplate>
<asp:HyperLink ID=”HyperLink1″ runat=”server” NavigateUrl=<%# Eval(“link”) %> Text=<%# Eval(“title“) %>></asp:HyperLink>
</ItemTemplate>
</asp:DataList>
<RssToolkit:rssdatasource id=”RssDataSource1″ runat=”server” url=”http://weblogs.asp.net/scottgu/Rss.aspx”>
</RssToolkit:rssdatasource>
</div>
</form>
</body>
</html>
asp.net rss toolkit(rss工具) _asp.net技巧
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » asp.net rss toolkit(rss工具) _asp.net技巧
相关推荐
-      对.net framework 反射的反思_asp.net技巧
-      .net3.5和vs2008中的asp.net ajax_asp.net技巧
-      使用asp.net ajax框架扩展html map控件_asp.net技巧
-      asp.net应用程序资源访问安全模型_asp.net技巧
-      photoshop初学者轻松绘制螺旋漩涡特效_photoshop教程
-      photoshop通道结合图层模式抠狗尾巴草_photoshop教程
-      web.config详解+asp.net优化_asp.net技巧
-      asp.net中多彩下拉框的实现_asp.net技巧