This code sample demonstrates how multiple RSS feeds can be combined, parsed, and displayed using the XmlTextReader and XmlTextWriter classes in the .NET framework. It can display all items found in one or more RSS feeds or display only a few items in a random manner. Ben Miller (Microsoft MVP Lead for ASP.NET, IIS, and Web Services) and I briefly discussed doing this and I ended up with this code sample as a result.
The code parses the RSS feeds using the XmlTextReader, creates an RSSItem struct for each item and adds it to an array. It then uses the array to generate a random list of feed items that can be displayed. The data within the array is converted into HTML by using the XmlTextWriter class. The XmlDocument class could have been used to merge the RSS feeds together as well but this example provides a more stream-based API that is less memory intensive.
|