Create RSS Feed in C#
This C# example demonstrates how to create an RSS feed from scratch using the Tortuga RSS .NET component (refer to http://www.worldwideweb-x.com/openData.html)
// This example demonstrates how to create an RSS feed from scratch. Tortuga.Rss rss = new Tortuga.Rss(); // We need a channel... Tortuga.Rss channel = rss.AddNewChannel(); // Fill in our channel information: channel.SetString("title","My RSS Feed"); channel.SetString("link","http://news.mygreatfeed.com/news"); channel.SetString("description","Top Stories in my Super-Duper News Feed"); channel.SetString("generator","Tortuga RSS"); channel.SetString("language","en"); channel.SetString("copyright"," 2005 MyGreatFeed"); channel.SetString("webMaster","[email protected]"); channel.SetDateNow("pubDate"); channel.SetDateNow("lastBuildDate"); // How about an image? Tortuga.Rss image = channel.AddNewImage(); image.SetString("title","My Great News"); image.SetString("url","http://www.mygreatfeed.com/news.gif"); image.SetString("link","http://www.mygreatfeed.com/"); // Add an item. Tortuga.Rss item = channel.AddNewItem(); item.SetString("title","Yahoo! Cooperates with Oppressive Chinese Regime"); String descrip = "Yahoo! passes information to the Chinese government to help convict a Chinese dissident. " + "Journalist Shi Tao is serving a 10-year prison sentence for revealing \"state secrets\"."; item.SetString("description",descrip); item.SetString("link","http://www.mygreatfeed.com/ShiTao.html"); item.SetString("guid","d78192a8"); item.SetAttr("guid","isPermaLink","false"); item.SetDateNow("pubDate"); // Add another item. item = channel.AddNewItem(); item.SetString("title","Clinton Neglects to Help Dissident Exposed by Yahoo!"); String descrip2 = "Former President Clinton fails to speak out for Shi Tao or defend freedom of speech on the Internet. "; item.SetString("description",descrip2); item.SetString("link","http://www.mygreatfeed.com/ClintonWeenie.html"); item.SetString("guid","d78192a9"); item.SetAttr("guid","isPermaLink","false"); item.SetDateNow("pubDate"); // Now get the complete XML for the RSS feed: textBox1.Text = rss.ToXmlString();
No comments: