The 3.5 .NET framework introduced a new SyndicationFeed class which simplifies the process of reading (and creating) RSS feeds. To try it out, I threw together a simple SSIS package which reads from an RSS feed using a Script Component.
Things to note:
The code for the script (notice I’m using C# which is only supported in SSIS 2008):
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute] public class ScriptMain : UserComponent { private string url = string.Empty; private SyndicationFeed feed = null; private XmlReader reader = null; public override void PreExecute() { base.PreExecute(); // Get the URL from the Http Connection Manager. // Note, we're not actually using the connection manager's connection object, // just it's URL setting. This is because using the .NET connection classes // give us more flexibility. reader = XmlReader.Create(Connections.HttpConnection.ConnectionString); feed = SyndicationFeed.Load(reader); } public override void PostExecute() { base.PostExecute(); reader.Close(); } public override void CreateNewOutputRows() { if (feed != null) { foreach (var item in feed.Items) { Output0Buffer.AddRow(); Output0Buffer.Title = item.Title.Text; Output0Buffer.PublishDate = item.PublishDate; Output0Buffer.LastUpdatedTime = item.LastUpdatedTime; Output0Buffer.Id = item.Id; Output0Buffer.Summary.AddBlobData(ConvertToBytes(item.Summary)); string authorName = string.Empty; if (item.Authors.Count > 0) { // take the first author authorName = item.Authors[0].Name; } Output0Buffer.Author = authorName; } Output0Buffer.SetEndOfRowset(); } } private byte[] ConvertToBytes(TextSyndicationContent content) { if (content != null && !string.IsNullOrEmpty(content.Text)) { // convert the string buffer to UTF8 so we can store it in an NTEXT column var encoding = new UTF8Encoding(); return encoding.GetBytes(content.Text); } return new byte[0]; } }
The package is available on my SkyDrive share:
来自Matt Masson: http://blogs.msdn.com/mattm/archive/2009/02/19/read-an-rss-feed-from-ssis.aspx 在.NET Framework
Fantastic! Just what I needed. Thank you.
Great post.... Works perfect. Thanks very much.
Hi
I used your solution and it was very good
But i have problem with some RSS feeds , I test many Feeds and it works good but some of them not works , this feed is an example that not works
www.alhalnews.com/rss.php
Pakage just shows an error about datetime parsing
can you test it?