Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 17th, 2008, 05:00 AM
Authorized User
 
Join Date: Jan 2008
Location: , , .
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default Rss feeds

Hi I want to write code that create a rss feed file from database everytime the programe runs. For somereason the below code is not displaying any thing:

**************
rss.aspx.vb
**************
Imports System.Text
Imports System.Xml
Imports System.Data
Imports System.Data.SqlClient


Partial Class rss
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

        Response.Clear()
        Response.ContentType = "text/xml"

        Dim xtw As XmlTextWriter = New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
        xtw.WriteStartDocument()
        Dim processtext As String = "type=\" & "text/xsl\" & " href=\" & "rss.xsl\"
        xtw.WriteProcessingInstruction("xml-stylesheet", processtext)
        xtw.WriteStartElement("rss")
        xtw.WriteAttributeString("version", "2.0")
        xtw.WriteStartElement("channel")
        xtw.WriteElementString("title", "Latest Articles List")
        xtw.WriteElementString("link", "http://www.yourwebsite.com/")
        xtw.WriteElementString("description", "some description here")

        Dim sql As String = "Select * from Articles"
        Dim constr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\db1.mdb"
        Dim da As New OleDb.OleDbDataAdapter(sql, constr)
        Dim dt As DataTable = New DataTable()
        da.Fill(dt)
        If dt.Rows.Count > 0 Then
            Dim i As Integer
            For i = 0 To dt.Rows.Count - 1 Step i + 1
                xtw.WriteStartElement("item")
                xtw.WriteElementString("title", dt.Rows(i)("Art_Title").ToString())
                xtw.WriteElementString("description", dt.Rows(i)("Art_Subject").ToString())
                xtw.WriteElementString("link", "http://www.yourwebsite.com/" + dt.Rows(i)("Art_Url").ToString())
                xtw.WriteElementString("pubDate", XmlConvert.ToString(Convert.ToDateTime(dt.Rows(i)( "L_Update").ToString())))
                xtw.WriteEndElement()
            Next
        End If

        xtw.WriteEndElement()
        xtw.WriteEndElement()
        xtw.WriteEndDocument()

        xtw.Flush()
        xtw.Close()

    End Sub
End Class


*********
rss.aspx
*********
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="rss.aspx.vb" Inherits="rss" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
</body>
</html>


********
rss.xsl
********
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="/">
    <html>
      <head>
        <title>
          <xsl:value-of select="/rss/channel/title" />
        </title>
      </head>
      <body>
        <table width="75%" border="1" cellspacing="1" cellpadding="1">
          <tr>
            <td bgcolor="#cccccc">
              <xsl:value-of select="/rss/channel/title" />
            </td>
          </tr>
        </table>

        <table width="75%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="15"></td>
          </tr>
          <tr>
            <td >
              This page is the sample syndication feed.
            </td>
          </tr>
          <tr>
            <td height="15"></td>
          </tr>
          <tr>
            <td>
              You can provide some Description about the RSS Feeds
            </td>
          </tr>
        </table>
        <table width="75%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="15"></td>
          </tr>
          <xsl:for-each select="/rss/channel/item">
            <tr>
              <td>
                <a href="{link}">
                  <xsl:value-of select="title" />
                </a>
              </td>
            </tr>
            <tr>
              <td height="5">
                <xsl:value-of select="description" />
              </td>
            </tr>
            <tr>
              <td height="10">

              </td>
            </tr>
          </xsl:for-each>
        </table>

      </body>
    </html>

  </xsl:template>

</xsl:stylesheet>
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rss feeds SKhna ASP.NET 2.0 Basics 3 March 20th, 2008 02:07 PM
Chapter 5 RSS Feeds NEO1976 BOOK: Professional Ajax ISBN: 978-0-471-77778-6 3 October 20th, 2006 11:34 PM
RSS Feeds with JavaScript NEO1976 Javascript How-To 0 October 6th, 2006 09:13 AM
RSS feeds from the forum? javatis Forum and Wrox.com Feedback 1 February 2nd, 2006 03:44 PM
RSS Feeds harpua PHP How-To 4 October 21st, 2005 09:59 AM



All times are GMT -4. The time now is 07:59 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.