Classic ASP XML Using ASP 3 and XML. See also the XML category for more XML discussions not relating to ASP. NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums . You are currently viewing the Classic ASP XML 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 .
December 5th, 2009, 06:59 AM
Authorized User
Join Date: Dec 2009
Posts: 84
Thanks: 16
Thanked 0 Times in 0 Posts
converting classic asp to an xml page
Hi there
Can anyone help me? I need to convert a classic asp page (driven from a database) to an xml page in order to be read by an rss reader.
Can anyone help me?
thanks
Adam
December 5th, 2009, 09:45 AM
Wrox Author
Points: 61,781, Level: 100
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 15,346
Thanks: 60
Thanked 1,193 Times in 1,174 Posts
Hi Adam,
I think you should start by showing us the relevant pieces of code from your current ASP page.
RSS is plain XML, so probably all you need is a few Response.Write statements in a loop for the records from your database / recordset.
Cheers,
Imar
December 6th, 2009, 08:02 AM
Authorized User
Join Date: Dec 2009
Posts: 84
Thanks: 16
Thanked 0 Times in 0 Posts
code for the page
Hi Imar
thanks for the speedy reply - I've pasted my code below that I want to appear as xml...
<%
strSQL = "SELECT id, name, email, blogimage, " & _
"threadid, thread, dateadded, detail " & _
"FROM tbl_comments " & _
"WHERE Approved = 1 ORDER BY dateadded DESC"
'response.Write(strSQL)
set rsFeedback = con.execute(strSQL)
if rsFeedback.EOF then
else
do while not rsFeedback.EOF
intid = rsFeedback("id")
strname = rsFeedback("name")
stremail = rsFeedback("email")
strblogimage = rsFeedback("blogimage")
intthreadid = rsFeedback("threadid")
intthread = rsFeedback("thread")
strdateadded = rsFeedback("dateadded")
strfeedback = rsFeedback("detail")
strfeedbacksml = rsFeedback("detail")
'strfeedbacksml = LEFT(CAST(rsFeedback("detail") as varchar(100)), 100)
if IsNull (intthreadid) or (intthreadid) = empty then
if isNull (strblogimage) or (strblogimage) = empty then
else
%>
<a href="<%=Application("Root_Path")%>images/blog/lrg_<%=strblogimage%>" rel="lightbox" title="<%=formatdatetime(strdateadded,2)%>"> <img src="<%=Application("Root_Path")%>images/blog/sml_<%=strblogimage%>" border="0" alt="Click to Enlarge" align="right" hspace="3" vspace="3"></a>
<%
end if
%>
<span class="spanb"><%=(replace(strFeedback, vbcrlf, "<br>"))%> <span class="spanb"><span class="bold">Posted by <span class="capitalize"><%=server.HTMLEncode(strname)%> </span></span>, [<%=formatdatetime(strdateadded, 2)%>]
<%
strSQL = "SELECT COUNT( * ) AS 'replies' FROM tbl_comments tbl_comments INNER JOIN tbl_comments tbl_comments2 ON " & _
"tbl_comments.threadid = tbl_comments2.id WHERE tbl_comments.approved = 1 AND tbl_comments.threadid = '" & intid & "'"
'response.Write(strSQL)
set rsThread = con.execute(strSQL)
intreplies = rsThread("replies")
%>
- <%=intreplies%> replies to this post - <a href="comment_ind.asp?thread=<%=intid%>">follow</a>
<%
set rsThread = nothing
rsFeedback.movenext()
loop
end if
set rsFeedback = nothing
%>
thanks
Adam
December 6th, 2009, 08:45 AM
Wrox Author
Points: 61,781, Level: 100
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 15,346
Thanks: 60
Thanked 1,193 Times in 1,174 Posts
Looks like you have most logic and code already in place. Rather than outputing span or other HTML elements, you now need to output XML elements that the RSS schema requires. E.g. rather than
<span class="spanb"><%=(replace(strFeedback, vbcrlf, "<br>"))%> <span class="spanb"><span class="bold">Posted by <span class="capitalize"><%=server.HTMLEncode(strname)%> </span></span>, [<%=formatdatetime(strdateadded, 2)%>]
You probably want to do something like:
Response.Write("<title>" + strname + "</title>")
In case you need more help on the RSS format:
http://www.google.com/search?hl=en&q...at+exam&aqi=g1
Cheers,
Imar
December 7th, 2009, 06:35 AM
Authorized User
Join Date: Dec 2009
Posts: 84
Thanks: 16
Thanked 0 Times in 0 Posts
asp to xml
Hi Imar
thanks for that - so would it be something like the below?
<%Response.write("<?xml version=""1.0"" encoding=""utf-8""?>")%>
<%Response.write("<?xml-stylesheet type=""text/css"" href=""css/rss.css"" ?>")%>
<%Response.write("<rss version=""2.0"">")%>
<%Response.write("<channel>")%>
<%Response.write("<title>Biosauce Blog</title>")%>
<%Response.write("<link>http://biosauce.com/blog.asp</link>")%>
<%Response.write("<description>Follow Our Blog</description>")%>
<%Response.write("<lastBuildDate>Mon, 7 Dec 2009 18:37:00 GMT</lastBuildDate>")%>
<%Response.write("<language>en-us</language>")%>
<%
strSQL = "SELECT id, name, email, blogimage, " & _
"threadid, thread, dateadded, detail " & _
"FROM tbl_comments " & _
"WHERE Approved = 1 ORDER BY dateadded DESC"
'response.Write(strSQL)
set rsFeedback = con.execute(strSQL)
if rsFeedback.EOF then
else
do while not rsFeedback.EOF
intid = rsFeedback("id")
strname = rsFeedback("name")
stremail = rsFeedback("email")
strblogimage = rsFeedback("blogimage")
intthreadid = rsFeedback("threadid")
intthread = rsFeedback("thread")
strdateadded = rsFeedback("dateadded")
strfeedback = rsFeedback("detail")
strFeedbacksml = Left(rsFeedback("detail"), 50)
if IsNull (intthreadid) or (intthreadid) = empty then
%>
<%Response.write("<item>")%>
<%Response.Write("<title>Posted by" + strname + "</title>")%>
<%Response.Write("<link>comment_ind.asp?thread=" + intid + "</link>")%>
<%Response.Write("<guid>follow</guid>")%>
<%Response.Write("<pubDate>" + formatdatetime(strdateadded, 2) + "</pubDate>")%>
<%Response.Write("<description>" + strFeedback + "</description>")%>
<%Response.write("</item>")%>
<!-- put more items here -->
<%
else
end if
rsFeedback.movenext()
loop
end if
set rsFeedback = nothing
%>
<%Response.write("</channel>")%>
<%Response.write("</rss>")%>
<%
con.close
set con = nothing
%>
thanks
Adam
December 7th, 2009, 08:18 AM
Wrox Author
Points: 61,781, Level: 100
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 15,346
Thanks: 60
Thanked 1,193 Times in 1,174 Posts
Hi Adam,
To make your code more easy to understand, you can get rid of all the script blocks. <% and %> denote a server side block. You don't have to open and close one on each line. E.g.:
<%Response.write("<?xml version=""1.0"" encoding=""utf-8""?>")%>
<%Response.write("<?xml-stylesheet type=""text/css"" href=""css/rss.css"" ?>")%>
Can be rewritten as:
<%
Response.write("<?xml version=""1.0"" encoding=""utf-8""?>")
Response.write("<?xml-stylesheet type=""text/css"" href=""css/rss.css"" ?>")
%>
Your entire code probably only needs a single script block.
You may need to tweak your code here and there. For example:
comment_ind.asp?thread
only makes sense within a web site where comment_ind.asp is used to point relatively to another page. RSS is disconnected from your site, so you need something like:
http://www.yourdoamin.com/comment_ind.asp?thread
Hope this helps,
Imar
December 7th, 2009, 09:07 AM
Authorized User
Join Date: Dec 2009
Posts: 84
Thanks: 16
Thanked 0 Times in 0 Posts
asp to xml
thanks Imar
Much appreciated.
I'm struggling to find the error with this line although when I output it it is giving me an error:
Response.Write("<link>
http://www.mydomain.com/comment_ind " + intid + "</link>")
can you advise?
thanks
Adam
December 7th, 2009, 09:44 AM
Wrox Author
Points: 61,781, Level: 100
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 15,346
Thanks: 60
Thanked 1,193 Times in 1,174 Posts
It would help if you'd say what error you're getting exactly.....
Imar
December 7th, 2009, 10:19 AM
Authorized User
Join Date: Dec 2009
Posts: 84
Thanks: 16
Thanked 0 Times in 0 Posts
asp to xml
sorry Imar
It's
<p>Microsoft VBScript runtime </font> <font face="Arial" size=2>error '800a000d'</font>
<p>
<font face="Arial" size=2>Type mismatch: '[string: "<link>http://www.bio"]'</font>
<p>
<font face="Arial" size=2>/blog2.asp</font><font face="Arial" size=2>, line 55</font>
thanks
Adam
December 7th, 2009, 10:58 AM
Wrox Author
Points: 61,781, Level: 100
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 15,346
Thanks: 60
Thanked 1,193 Times in 1,174 Posts
Try using an ampersand instead of a plus:
Response.Write("<link>
http://www.mydomain.com/comment_ind " & intid & "</link>")
Since intid seems to be a number, I think the compiler tries to add the three values, rather than concatenate them...
Imar
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off