Perform the XSLT Transform
There are three sample projects in the downloadable code
for this article. The first is a class library project containing a class called DevXRSS that exposes the getXMLFeed
method shown earlier in this article. It also exposes a getHTMLFeed
method which retrieves the raw XML RSS document, and then applies the XSLT stylesheet shown in the preceding section of this article. As you'll see, you don't need a special wrapper function to retrieve and display DevX's pre-built HTML. The other two projects are functionally equivalent Windows Forms and Web Forms (ASP.NET) applications that display the feeds in various forms.
Public Function getHTMLFeed(ByVal URL As String) _
Dim erReader As New EmbeddedResourceReader
Dim s As String = _
If s.Length > 0 Then
' load the XSLT Stylesheet
Dim xsl As New XslTransform
Dim st As New StringReader(s)
xsl.Load(New XmlTextReader(st), _
Nothing, [Assembly]. _
' retrieve the xml
Dim xml As New XmlDocument
' perform the XSL transform
Dim args As New XsltArgumentList
Dim wrtr As XmlTextWriter
Dim sb As New StringBuilder
Dim sw As New StringWriter(sb)
wrtr = New XmlTextWriter(sw)
args, wrtr, New XmlUrlResolver)
Dim sRet As String = sb.ToString
The stylesheet itself (DevxRSS.xsl) is an embedded file. The method retrieves the string contents using the EmbeddedResourceReader class included with the project, and then loads that string into a new XslTransform instance. It retrieves the RSS document using the getXMLFeed method, and then calls one of the XslTransform object's overloaded Transform methods, passing in an XmlNavigator, an empty XsltArgumentList (required, but not used here), an XmlTextWriter instance, and a new XmlUrlResolver instance (required, but not used here). This particular version of the Transform method uses an XmlTextWriter to write the transformed content to an underlying StringBuilder. The method returns the StringBuilder contents.
DevX RSS Feed Examples
| Figure 2. Viewing the Feed: In the sample application, you can hit the "Show Transformed RSS" button to invoke the getHTMLFeed method, which displays the feed in human-readable HTML.|
You can use the feeds in either a Windows Forms application or an ASP.NET application. The sample Windows Forms project, called TestDevXRSS, contains one form with an embedded WebBrowser control, and three buttons. The first button, "Show RSS Document," calls the getXMLFeed
method and displays the raw XML in the embedded browser (see Figure 1
The second button, "Show Transformed RSS" calls the getHTMLFeed method and displays the result of the XSLT Transform (see Figure 2).
The third button "Show DevX HTML Feed" simply tells the browser to navigate to the URL that returns the DevX-generated HTML for the feed (see Figure 3).
| Figure 3. Pre-formatted HTML: The Show DevX HTML Feed button uses an IFRAME tag to request the pre-formatted content from DevX. Although this is quick and convenient, you have little control over how the content appears.|
An ASP.NET Web project (also included with the sample code) relies on the same feeds and the same transformation as the Windows Forms project. Figure 4
shows the DevX HTML feed in the IFRAME.
The ASP.NET application's functionality is essentially identical to that of the Windows Forms application. While the Windows Forms application uses an embedded WebBrowser control to display the content, the Web Forms application uses an IFRAME (which is essentially a WebBrowser control embedded in the browser's window) to display the same content.
When a user clicks one of the buttons in the Web Form project, the form posts back to the server. The code-behind for each button uses a Label control on the page as a placeholder to insert an <IFRAME> tag into the generated page. You simply set the Label's Text property to the HTML for the IFRAME. The ASP.NET engine then sends the text to the browser, which parses the label's text as HTML and creates the IFRAME control on the client. The IFRAME then requests the content and displays it in the IFRAME control. Using the Label control as a placeholder for the IFRAME isn't strictly required; you could just write the <IFRAME> tag directly, using the HttpResponse object, but it is convenient.
Using both Windows Forms and Web Forms should serve to illustrate how easy it is to display RSS content and how XML is transforming the concepts of programming. XML, as RSS feeds or as Web services, is changing the way people design and develop applications
| Figure 4. ASP.NET Version: The ASP.NET version of the sample application is functionally identical to the Windows Forms version shown in Figures 1 through 3.|
We encourage you to include DevX's feeds
in your own applications. Besides the general feed, which includes all feature articles and tutorials, as they are published, the following technology-specific feeds are also available:
- Web Development