1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Rss in classic asp

Discussion in 'C#' started by okpara36, Jul 27, 2009.

  1. #1
    Hello,

    I really need to know how to create RSS IN CLASSIC ASP
    I want to show 10 top news.


    thanks
     
    okpara36, Jul 27, 2009 IP
  2. dwirch

    dwirch Well-Known Member

    Messages:
    239
    Likes Received:
    12
    Best Answers:
    1
    Trophy Points:
    135
    #2
    Basically, you're going to read the content of your database, reformat the content into XML, and save it to a file.

    However, did you know that you don't have to have an XML extension on your RSS feed? You *can* have an .asp extension, and readers will accept it just fine.

    Below is some sample code from an old site of mine, properly sanitized. Just change the connection string info, sql query, and fields to use, and you should be able to drop this right in.

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <% Response.Buffer = true
       Response.ContentType = "text/xml"
       
    Function ApplyXMLFormatting(strInput)
      strInput = Replace(strInput,"&", "&amp;")
      strInput = Replace(strInput,"'", "'")
      strInput = Replace(strInput,"""", "&quot;")
      strInput = Replace(strInput, ">", "&gt;")
      strInput = Replace(strInput,"<","&lt;")
      
      ApplyXMLFormatting = strInput
    End Function
    
    Function stripHTML2(strHTML)
    'Strips the HTML tags from strHTML using split and join
    
      'Ensure that strHTML contains something
      If len(strHTML) = 0 then
        stripHTML = strHTML
        Exit Function
      End If
    
      dim arysplit, i, j, strOutput
    
      arysplit = split(strHTML, "<")
     
      'Assuming strHTML is nonempty, we want to start iterating
      'from the 2nd array postition
      if len(arysplit(0)) > 0 then j = 1 else j = 0
    
      'Loop through each instance of the array
      for i=j to ubound(arysplit)
         'Do we find a matching > sign?
         if instr(arysplit(i), ">") then
           'If so, snip out all the text between the start of the string
           'and the > sign
           arysplit(i) = mid(arysplit(i), instr(arysplit(i), ">") + 1)
         else
           'Ah, the < was was nonmatching
           arysplit(i) = "<" & arysplit(i)
         end if
      next
    
      'Rejoin the array into a single string
      strOutput = join(arysplit, "")
      
      'Snip out the first <
      strOutput = mid(strOutput, 2-j)
      
      'Convert < and > to &lt; and &gt;
      strOutput = replace(strOutput,">","&gt;")
      strOutput = replace(strOutput,"<","&lt;")
    
      stripHTML2 = strOutput
      
    End Function
        %>
    <rss version="2.0">
      <channel>
        <title>Recent News on FortyPoundHead.com</title>
        <link>http://www.fortypoundhead.com/</link>
        <description>Windows won't open? Linux got you 
    	flummoxed? Ask the Forty Pound Head your IT questions,
    	get the right answer!</description>
        <language>en-us</language>
        <copyright>Copyright 2008 Derek Wirch. 
           All Rights Reserved.</copyright>
        <lastBuildDate><%=Now()%></lastBuildDate>
        <ttl>20</ttl>
    <%
      Dim MyContent
      Dim objConn
      Set objConn = Server.CreateObject("ADODB.Connection")
      
      objConn.ConnectionString = "Driver={MySQL ODBC 5.1 Driver};Server=MyServer;Database=MyDatabase;User=MyUsername; Password=MyPassword;Option=3;"
      objConn.Open
        
      Dim objRS, strSQL, strDesc 
    
      strSQL="SELECT * FROM MyTable ORDER BY UniqueID DESC LIMIT 10"
      Set objRS = objConn.Execute(strSQL)  
    
      Do While Not objRS.EOF
    	MyContent=objRS("MainContent")
    	MyContent=StripHTML2(left(MyContent,200))
    	MyContent=ApplyXMLFormatting(MyContent)
    	
      %>
        <item>
          <title><%=ApplyXMLFormatting(objRS("ContentTitle").Value)%></title>
          <link>http://www.MySiteName.com/MyPage.asp?UniqueID=<%=objRS("UniqueID")%></link>
          <datePosted><%=ApplyXMLFormatting(objRS("ContentPostDate"))%></datePosted>
    	  <description><% =MyContent %></description>
        </item>
        <%
        objRS.MoveNext
      Loop
      
      objRS.Close
      Set objRS = Nothing
    
      objConn.Close
      Set objRS = Nothing
      Set objConn = Nothing
    %>
      </channel>
    </rss>
    
    Code (markup):
     
    dwirch, Jul 27, 2009 IP
  3. prptl709

    prptl709 Guest

    Messages:
    83
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I am not used rss in asp but in future I am using in my application.
     
    prptl709, Mar 1, 2011 IP
  4. mrkhm

    mrkhm Well-Known Member

    Messages:
    224
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #4
    thanks to dwirch! this was a very useful "copy and paste" tutorial that worked "out of the box" in 10 mins, time saver. thanks.
     
    mrkhm, Feb 28, 2012 IP
  5. dwirch

    dwirch Well-Known Member

    Messages:
    239
    Likes Received:
    12
    Best Answers:
    1
    Trophy Points:
    135
    #5
    no problem. glad you got some use out of it!
     
    dwirch, Feb 28, 2012 IP
  6. dwirch

    dwirch Well-Known Member

    Messages:
    239
    Likes Received:
    12
    Best Answers:
    1
    Trophy Points:
    135
    #6
    Please note that this method does not provide a style sheet (XSL). You will get an error (The XML page cannot be displayed Cannot view XML input using XSL style sheet) saying as much if you are trying to view the XML with a browser that expects the stylesheet to be present.

    FYI: Style sheets are just there to make the XML more "human readable".
     
    dwirch, Jan 14, 2013 IP
  7. njwebsitedesign

    njwebsitedesign Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hi dwirch,

    We're getting the following error when attempting to implement your example:

    This page contains the following errors:
    error on line 18 at column 17: AttValue: " or ' expected

    Below is a rendering of the page up to the first error.

    Is there a missing " or ' right enough?

    NJ
     
    njwebsitedesign, Jan 14, 2013 IP
  8. dwirch

    dwirch Well-Known Member

    Messages:
    239
    Likes Received:
    12
    Best Answers:
    1
    Trophy Points:
    135
    #8
    Can you post the section of code ? My copy of the code doesn't match up (it's a commented line in my copy).


    edit:

    I did notice this on line 8:

    strInput = Replace(strInput,"""", "&quot;")

    You can change the """" to chr(34), so that it looks like:

    strInput = Replace(strInput,chr(34), "&quot;")
     
    Last edited: Jan 14, 2013
    dwirch, Jan 14, 2013 IP
  9. njwebsitedesign

    njwebsitedesign Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Of course, sorry...

     0 then j = 1 else j = 0  'Loop through each instance of the array for i=j to ubound(arysplit)     'Do we find a matching > sign?     if instr(arysplit(i), ">") then       'If so, snip out all the text between the start of the string       'and the > sign       arysplit(i) = mid(arysplit(i), instr(arysplit(i), ">") + 1)     else       'Ah, the < was was nonmatching       arysplit(i) = "",">")  strOutput = replace(strOutput,"
    
    What is going on here?
    The board doesn't seem to be picking up on my [code] snippet.  Am I missing something here?
    Code (markup):
     
    njwebsitedesign, Jan 14, 2013 IP
  10. njwebsitedesign

    njwebsitedesign Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
     0 then j = 1 else j = 0  'Loop through each instance of the array for i=j to ubound(arysplit)     'Do we find a matching > sign?     if instr(arysplit(i), ">") then       'If so, snip out all the text between the start of the string       'and the > sign       arysplit(i) = mid(arysplit(i), instr(arysplit(i), ">") + 1)     else       'Ah, the < was was nonmatching       arysplit(i) = "",">")  strOutput = replace(strOutput,"
    Code (markup):
     
    njwebsitedesign, Jan 14, 2013 IP
  11. njwebsitedesign

    njwebsitedesign Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I've wrapped my code in the [ code ] and [ / code ] brackets but it just won't display. Is this something to do with being a new member?
     
    njwebsitedesign, Jan 14, 2013 IP
  12. dwirch

    dwirch Well-Known Member

    Messages:
    239
    Likes Received:
    12
    Best Answers:
    1
    Trophy Points:
    135
    #12
    See your PMs.
     
    dwirch, Jan 14, 2013 IP