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,"&", "&") strInput = Replace(strInput,"'", "'") strInput = Replace(strInput,"""", """) strInput = Replace(strInput, ">", ">") strInput = Replace(strInput,"<","<") 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 < and > strOutput = replace(strOutput,">",">") strOutput = replace(strOutput,"<","<") 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):
thanks to dwirch! this was a very useful "copy and paste" tutorial that worked "out of the box" in 10 mins, time saver. thanks.
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".
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
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,"""", """) You can change the """" to chr(34), so that it looks like: strInput = Replace(strInput,chr(34), """)
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):
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):
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?