Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
|
Read RSS FeedSample code showing how to read an RSS feed and display the contents. The Chilkat RSS class/component is freeware. Note: The Chilkat XML ActiveX also includes the Chilkat RSS and Atom components. CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @sTmp0 nvarchar(4000) DECLARE @rss int EXEC @hr = sp_OACreate 'Chilkat.Rss', @rss OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int -- Download from the feed URL: EXEC sp_OAMethod @rss, 'DownloadRss', @success OUT, 'http://blog.chilkatsoft.com/?feed=rss2' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @rss, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Get the 1st channel. DECLARE @rssChannel int EXEC sp_OAMethod @rss, 'GetChannel', @rssChannel OUT, 0 IF @rssChannel Is NULL BEGIN PRINT 'No channel found in RSS feed.' RETURN END -- Display the various pieces of information about the channel: EXEC sp_OAMethod @rssChannel, 'GetString', @sTmp0 OUT, 'title' PRINT 'Title: ' + @sTmp0 EXEC sp_OAMethod @rssChannel, 'GetString', @sTmp0 OUT, 'link' PRINT 'Link: ' + @sTmp0 EXEC sp_OAMethod @rssChannel, 'GetString', @sTmp0 OUT, 'description' PRINT 'Description: ' + @sTmp0 -- For each item in the channel, display the title, link, -- publish date, and categories assigned to the post. DECLARE @numItems int EXEC sp_OAGetProperty @rssChannel, 'NumItems', @numItems OUT DECLARE @i int SELECT @i = 0 WHILE @i <= @numItems - 1 BEGIN DECLARE @rssItem int EXEC sp_OAMethod @rssChannel, 'GetItem', @rssItem OUT, @i PRINT '----' EXEC sp_OAMethod @rssItem, 'GetString', @sTmp0 OUT, 'title' PRINT 'Title: ' + @sTmp0 EXEC sp_OAMethod @rssItem, 'GetString', @sTmp0 OUT, 'link' PRINT 'Link: ' + @sTmp0 EXEC sp_OAMethod @rssItem, 'GetString', @sTmp0 OUT, 'pubDate' PRINT 'pubDate: ' + @sTmp0 DECLARE @numCategories int EXEC sp_OAMethod @rssItem, 'GetCount', @numCategories OUT, 'category' DECLARE @j int IF @numCategories > 0 BEGIN SELECT @j = 0 WHILE @j <= @numCategories - 1 BEGIN EXEC sp_OAMethod @rssItem, 'MGetString', @sTmp0 OUT, 'category', @j PRINT ' category: ' + @sTmp0 SELECT @j = @j + 1 END END SELECT @i = @i + 1 END END GO |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.