VB Orcas RSS Feeder example

Orcas Beta 1 samples include a RSS feeder for C#, but there isn’t one for VB, so I thought I’d slap one together.  Some things to note compared to the C# one is the use of XML literals an expressions.  Also note the use of LINQ expressions rather than using yield and custom enumerators.. the result is the same in terms of delayed evaluation even though this example doesn’t actually show that 😉
Option Strict On : Option Explicit On : Option Infer On
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Xml
Imports System.Xml.Linq
Module Module1
   Const feedURL As String = “http://+:8086/vbfeeds/”
   Const feedURI As String = “http://localhost:8086/vbfeeds/”
   Function GetItems() As IEnumerable(Of XElement)
      Dim feeds() As String = {“http://msmvps.com/blogs/bill/rss.aspx”, _
      “http://blogs.msdn.com/vbteam/rss.aspx”, _
     “http://www.panopticoncentral.net/Rss.aspx”, _
      “http://blogs.msdn.com/xmlteam/rss.aspx”, _
      Return From feed In feeds _
         From item In XDocument.Load(feed).Root.<channel>.<item> _
         Select item
   End Function
   Function GetReplyBody() As XElement
      Return <rss version=“2.0”>
                  <title>VB Geeks</title>
                  <link><%= feedURL %></link>
                  <description>VB bloggers</description>
                  <generator>XLinq-based RSS aggregator</generator>
                  <%= GetItems.ToArray %>
   End Function
   Sub Main()
      Dim listener As New Net.HttpListener()
      Console.WriteLine(“starting server”)
      Console.WriteLine(“opening browser pointed at this server”)
      Diagnostics.Process.Start(“iexplore.exe”, feedURI)
      While True
         Dim response = listener.GetContext.Response
         response.ContentType = “text/xml”
         Using writer As New XmlTextWriter(response.OutputStream, Text.Encoding.UTF8)
         End Using
      End While
   End Sub
End Module
‘ for those interested this is the original C# source :
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
using System.Linq;
using System.Xml.Linq;
using System.Net;
// See the ReadMe.html for additional information
class app
   const string feedUrl = “http://+:8086/csharpfeeds/”;
   static IEnumerable<XElement> GetItems()
      string[] feeds = {
      foreach (var str in feeds)
         var feed = XDocument.Load(str);
         var items = feed.Root.Element(“channel”).Elements(“item”);
         foreach (var item in items)
            yield return item;
   static XElement GetReplyBody()
      return new XElement(“rss”,
         new XAttribute(“version”“2.0”),
         new XElement(“channel”,
            new XElement(“title”“C# Geeks”),
            new XElement(“link”, feedUrl),
            new XElement(“description”“C# Team Members”),
            new XElement(“generator”“XLinq-based RSS aggregator”),
   static void Main()
      var listener = new HttpListener();
      // Open a browser pointing at the feeds being served.
      string uri = @”http://localhost:8086/csharpfeeds/”;
      System.Diagnostics.Process browser = new System.Diagnostics.Process();
      browser.StartInfo.FileName = “iexplore.exe”;
      browser.StartInfo.Arguments = uri;
      // Serve requests.
      while (true)
         var context = listener.GetContext();
         var body = GetReplyBody();
         context.Response.ContentType = “text/xml”;
         using (XmlWriter writer = new XmlTextWriter(context.Response.OutputStream, Encoding.UTF8))

1 Comment so far

  1.   Nick on April 21st, 2007          

    Great conversion. I love that VB has all these cryptic options now. I just hope that Orcas will default them all to On at project level (for new projects at least)