Click here to Skip to main content
11,705,610 members (46,750 online)
Click here to Skip to main content

Visual Studio .NET RSS Viewer with XSL

, 9 Mar 2004 CPOL 48.5K 516 16
Rate this:
Please Sign up or sign in to vote.
Another macro to show an RSS feed in VS.NET, nicely formatted using the CP colors

Introduction

RSS feeds are more and more popular and as any site that respects itself, CodeProject also provides a nice RSS feed with information about the latest articles.

As Steven Hicks just noticed in the Lounge http://www.codeproject.com/lounge.asp#xx761109xx CodeProject RSS link is not so easy to notice. If you are a real CPA (CodeProjectAdict) you do want to see "What's new on CP" at any moment. And the best place to see it is of course in you VS.Net environment where you spend most of you time anyway. Plus that you don't have to open a new explorer window just to see if there is anything new on CP.

And if you could also see the latest news in the CodeProject style (colors, fonts) it would be even nicer.

Sample screenshot

XSL

Thus, to achive this goal I made a small XSL file to translate the RSS from CP to a nice formated HTML webpage that gets displayed inside VS.Net but a simple mouse click.

Macro

The macro is based 99% on the one provided by Davy Mitchell in his article Visual Studio .NET RSS Headline Viewer.

Function GetHTML(ByVal strPage As String) As String

    If strPage.StartsWith("http://") Then
        Try
            Dim oReq As System.Net.HttpWebRequest
            Dim oResp As System.Net.HttpWebResponse
            oReq = System.Net.HttpWebRequest.Create(strPage)
            oResp = oReq.GetResponse
            Dim sr As New StreamReader(oResp.GetResponseStream)
            Return sr.ReadToEnd()
        Catch
            'Do something with your error
        End Try
    Else    ' local file ?
        Dim sr As StreamReader = New StreamReader(strPage)
        Return sr.ReadToEnd()
    End If

End Function


Public Sub RefreshRSS()
    Try
        'DESCRIPTION: Grabs headlines and displays them as text.
        Dim RDFText As String
        Dim objTextDoc As TextDocument
        Dim objEP As EditPoint

        'Create a new text document.
        Call DTE.ItemOperations.NewFile("General\Text File")

        'Get a handle to the new document.
        objTextDoc = DTE.ActiveDocument.Object("TextDocument")
        objEP = objTextDoc.StartPoint.CreateEditPoint
        RDFText = GetHTML(http://www.codeproject.com/ & _
              "webservices/articlerss.aspx?cat=3")

        objEP.Insert("<?xml-stylesheet type=""text/xsl"" " & _
              "href=""change.xsl""?>" + vbCrLf)

        RDFText = RDFText.Replace("©", "(c)")

        objEP.Insert(RDFText)

        'Store
        ActiveDocument.Save("C:\\temp\\news.xml")
        ActiveDocument.Close()

        Dim ItemOp As ItemOperations
        ItemOp = DTE.ItemOperations
        ItemOp.Navigate("file://C:\temp\news.xml", _
              vsNavigateOptions.vsNavigateOptionsDefault)

    Catch err As System.Exception
        MsgBox(err.ToString)
    End Try
End Sub

Usage

  • Unzip the files to a folder of your choice (C:\temp) for example.
  • Drop this macro in your macro editor, assign the macro to a button and update the paths in the macro with the path where you unziped the files.
  • Click the button Smile | :) .

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Corneliu Tusnea
Technical Lead OneSaas - Cloud Integrations Made Easy
Australia Australia

You may also be interested in...

Comments and Discussions

 
GeneralProblems with special characters Pin
Lpalma10-Jun-05 16:28
memberLpalma10-Jun-05 16:28 
Generalbetter... Pin
Anonymous16-Mar-04 19:05
sussAnonymous16-Mar-04 19:05 
GeneralRe: better... Pin
rkiesler17-Mar-04 6:18
memberrkiesler17-Mar-04 6:18 
Not only that, but some versions of IE (MSXML, rather) won't transform this XML since the XSL processing instruction is inserted _before_ the XML declaration, which is invalid. Modified code:

Public Sub RefreshRSS()
Try
'DESCRIPTION: Grabs headlines and displays them as text.
Dim RDFText As String
Dim objTextDoc As TextDocument
Dim objEP As EditPoint
Dim pos As Integer
Dim doc As New XmlDocument
Dim tx As New XslTransform

'Create a new text document.
Call DTE.ItemOperations.NewFile("General\Text File")

'Get a handle to the new document.
objTextDoc = DTE.ActiveDocument.Object("TextDocument")
objEP = objTextDoc.StartPoint.CreateEditPoint

RDFText = GetHTML("http://www.codeproject.com/webservices/articlerss.aspx?cat=3")
RDFText = RDFText.Replace("©", "(c)")

objEP.Insert(RDFText)

'Store
ActiveDocument.Save("C:\\temp\\news.xml")
ActiveDocument.Close()

doc.Load(New XmlTextReader("C:\\temp\\news.xml"))
tx.Load("c:\\temp\\change.xsl")
Dim fs As FileStream = New FileStream("C:\\temp\\news.html", FileMode.OpenOrCreate)
tx.Transform(doc.CreateNavigator(), Nothing, fs, Nothing)

Dim ItemOp As ItemOperations
ItemOp = DTE.ItemOperations
ItemOp.Navigate("file://C:\temp\news.html", _
vsNavigateOptions.vsNavigateOptionsDefault)

Catch err As System.Exception
MsgBox(err.ToString)
End Try
End Sub
General[Message Removed] Pin
immetoz1-Oct-08 9:45
memberimmetoz1-Oct-08 9:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150819.1 | Last Updated 10 Mar 2004
Article Copyright 2004 by Corneliu Tusnea
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid