PDA

View Full Version : Problem Using XML to Create RSS Feed


SteveSensei
11-24-2009, 11:56 PM
I am creating an RSS feed by polling a database of products using ASP and writing the file:

TBdy = ""
set fso = server.createobject("scripting.filesystemobject")
'set wf = fso.opentextfile(server.mappath("\rss\BowlersWherehouse.rss"), 8, true) 'Append
set wf = fso.opentextfile(server.mappath("\rss\BowlersWherehouse.rss"), 2, true) 'Write
TBdy = "<?xml version='1.0' encoding='utf-8'?>" & Chr(13) & Chr(10)
TBdy = TBdy & "<rss version='2.0'>" & Chr(13) & Chr(10)
TBdy = TBdy & "<channel>" & Chr(13) & Chr(10)
TBdy = TBdy & "<lastBuildDate>" & CurrDateT & "</lastBuildDate>" & Chr(13) & Chr(10)
TBdy = TBdy & "<ttl>240</ttl>" & Chr(13) & Chr(10)
TBdy = TBdy & "<title>BowlersWherehouse.com</title>" & Chr(13) & Chr(10)
TBdy = TBdy & "<link>http://www.bowlerswherehouse.com</link>" & Chr(13) & Chr(10)
TBdy = TBdy & "<description>BowlersWherhouse.com Products</description>" & Chr(13) & Chr(10)
TBdy = TBdy & "<language>en-us</language>" & Chr(13) & Chr(10)
TBdy = TBdy & "<copyright>Copyright 2009 BowlersWhewrehouse.com. All Rights Reserved.</copyright>" & Chr(13) & Chr(10)
TBdy = TBdy & "<image>" & Chr(13) & Chr(10)
TBdy = TBdy & "<url>http://www.bowlerswherehouse.com/graphics/alternateHeader.jpg</url>" & Chr(13) & Chr(10)
TBdy = TBdy & "<title>BowlersWherehouse.com</title>" & Chr(13) & Chr(10)
TBdy = TBdy & "<link>http://www.bowlerswherehouse.com</link>" & Chr(13) & Chr(10)
TBdy = TBdy & "</image>" & Chr(13) & Chr(10)


While ((Repeat1__numRows <> 0) AND (NOT rsProducts.EOF))
image = (rsProducts.Fields.Item("image").Value)
recordID = (rsProducts.Fields.Item("recordID").Value)
product = (rsProducts.Fields.Item("prodName").Value)

prodDesc = stripHTML(rsProducts.Fields.Item("longDescription").Value)
prodDesc = Replace(prodDesc, chr(180), "'")
prodDesc = Replace(prodDesc, "´", "'")
prodDesc = Replace(prodDesc, "&", "&")

TBdy = TBdy & "<item>" & Chr(13) & Chr(10)
TBdy = TBdy & "<title>" & product & "</title>" & Chr(13) & Chr(10)
TBdy = TBdy & "<image>http://www.bowlerswherehouse.com/productPhotos/" & image & "</image>" & Chr(13) & Chr(10)
TBdy = TBdy & "<guid>http://www.bowlerswherehouse.com/prodDetail.asp?recordID=" & recordID & "</guid>" & Chr(13) & Chr(10)
TBdy = TBdy & "<description>" & prodDesc & "</description>" & Chr(13) & Chr(10)
TBdy = TBdy & "<link>http://www.bowlerswherehouse.com/prodDetail.asp?recordID=" & recordID & "</link>" & Chr(13) & Chr(10)
TBdy = TBdy & "</item>" & Chr(13) & Chr(10)
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsProducts.MoveNext()
Wend

TBdy = TBdy & "</channel>" & Chr(13) & Chr(10)
TBdy = TBdy & "</rss>"

wf.writeline(Tbdy)
'Response.Write Tbdy
wf.close
set wf = nothing
set fso = nothing

The resulting file looks like this (prouct list shortened for brevity):



<rss version='2.0'>
<channel>
<lastBuildDate>Mon, 23 Nov 2009 12:45:34 PST</lastBuildDate>
<ttl>240</ttl>
<title>BowlersWherehouse.com</title>
<link>http://www.bowlerswherehouse.com</link>
<description>BowlersWherhouse.com Products</description>
<language>en-us</language>
<copyright>Copyright 2009 BowlersWhewrehouse.com. All Rights Reserved.</copyright>
<image>
<url>http://www.bowlerswherehouse.com/graphics/alternateHeader.jpg</url>
<title>BowlersWherehouse.com</title>
<link>http://www.bowlerswherehouse.com</link>
</image>
<item>
<title>Brunswick Avalanche Slide</title>
<url>http://www.bowlerswherehouse.com/slide.jpg</url>
<guid>http://www.bowlerswherehouse.com/slide.jpg</guid>
<description>Retro cores and strong reactive coverstocks define the new Avalanche series from Brunswick. Using proven core technology from the Teal Rhino Pro and some of Brunswick''s most well know coverstocks, the Avalanche delivers unprecedented value to the bowling customer.Lane Condition: Medium Coverstock: Reactive Resin RG: 2.548 Finish: Polished Color: Red / Black Pearl Performance: Mid Performance</description>
<link>http://www.bowlerswherehouse.com/prodDetail.asp?recordID=300</link>
</item>
</channel>
</rss>

My problem is that I always get a blank line at the beginning of the file, before the line <rss version='2.0'>, which is causing errors. Does anyone know how to get rid of the blank first line?

Alex Vincent
11-25-2009, 02:12 AM
TBdy = "<?xml version='1.0' encoding='utf-8'?>" & Chr(13) & Chr(10)


As I recall, 13 means "new line" or "carriage return". :-) I have no idea what 10 is in ASCII.

oesxyl
11-25-2009, 01:59 PM
As I recall, 13 means "new line" or "carriage return". :-) I have no idea what 10 is in ASCII.
ms "newline", "\r\n", :)

best regards

Cannan_moore
02-12-2010, 09:03 AM
Hey guys :)
I want to create a rss feed for dynamic album, such as recent update album, then my friends can simply watch that feed to keep track of all my gallery update, is this possible?
http://www.rsschannelwriter.com/

Dormilich
02-12-2010, 10:43 AM
I want to create a rss feed for dynamic album, such as recent update album, then my friends can simply watch that feed to keep track of all my gallery update, is this possible?

ain’t that what feeds were created for?