Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing an RSS feed with ASP 1

Status
Not open for further replies.

mtarby

Programmer
Feb 19, 2003
89
US
What I'd like to do is take the contents of our news database, write it dynamically into an xml file, then write a page to display the feed.

So far, I've gotten the part to write the xml file to work, but am having a problem with part 2. One of the tutorials I came across suggested using the following:

Code:
<%
Function getXML(sourceFile) 
dim styleFile 
dim source, style 
styleFile = Server.MapPath("/admission/rss/news.xsl")

Dim xmlhttp
Set xmlhttp = Server.CreateObject("Microsoft.XMLHTTP")
xmlhttp.Open "GET", sourceFile, false
xmlhttp.Send

set source = Server.CreateObject("Microsoft.XMLDOM")
source.async = false 
source.loadxml(xmlhttp.ResponseText) 

set style = Server.CreateObject("Microsoft.XMLDOM")
style.async = false 
style.load(styleFile) 

getXML = source.transformNode(style) 
set source = nothing 
set style = nothing 
End Function 

Response.ContentType = "text/xml"

%>

Except I get a message saying "This XML file does not appear to have any style information associated with it. The document tree is shown below."

Any ideas or suggestions as to what I'm doing wrong? I thought I set up a valid style file...

Thanks in advance.

Michelle
 
Ok, I'm not sure I understand what your doing. You have an XSL sheet to transform the XML from a remote location, but then you want to output that as XML also?

In terms of client-side processing of an XML document, it only knows that a style sheet has been associated with an XML document if the XML file has an ?xml-stylesheet element near the beginning of the document.

If a,ll you want to do is output an RSS file when someone comes to a certain page addres then you don't need XMLHTTP or even an XSL sheet. Simply set the ContentType to text/xml and make sure your outputting well-formatted XML. I guess I don't understand quite what your doing...

-T

barcode_1.gif
 
Thanks - that helps clear things up a bit for me. All I'm trying to do is actually output the XML file.

This is the first time I've tried to do this, so I've been reading all these tutorials online and trying to put the information together in a way I thought it would work. All I've succeeded in doing is confusing myself!



 
Ok, then we can boil it down quite a bit. Basically what you will want to do is build a SELECT statement to pull a certain number of items from your database, preferably ordered by some timestamp and limited to 20 or so items (we don't want the file to be that large).
Set the Response.ContentType to "text/xml".
Then all you will need to do is loop through the resulting recordset and output the data inside XML tags. ASP doesn't care if it is outputting HTML, XML, CSV, or whatever, so you can just use response.Write's to output the XML tags and data.

Thats it :)

Now you will probably want to consider complicating this a little more after you get it working. Fo instance, there is no point in dynamically generating the XML every single time someone requests it if it is only changing once in a while - ie, if you get 50 requests an hour and it only changes once an hour, then it would be awful nice if we could just cache the file the first time and serve out copies the other 49 times. One method of caching the file would be to output an XML file when someone submits new news items (from whatever submission page you have set up). That way you would add their entry to the db, build the xml file, and save it locally using a FileSystemObject. At this point anyone that requests the file can simply get a copy of te static file that should always be up to date with the newest news items.
Another method would be to only pull out the top record (most recent) and compare the data against the last modified date on a cache file. If the date is newer (or the cache file doesn't exist), pull out the 20 or so records, build the XCML, write it to your cache file, and ten send it to the end user. If the database date is less then the cache file lastModified date then simply send them the cache file.

Anyways, my suggestion would be to get a very simple version up first as I outlined in the beginning. This will give you something working right away and a platform to try out other things. That way if something isn't working at least you'll be working from a solid, working base, so it will be that much less logic you would have to check to find any errors.

-T

barcode_1.gif
 
This is moving along MUCH better now (and makes more sense to me!) Thanks so much for getting me on the right path!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top