p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Classic ASP XML (http://p2p.wrox.com/forumdisplay.php?f=69)
-   -   converting classic asp to an xml page (http://p2p.wrox.com/showthread.php?t=77308)

adamhw December 5th, 2009 07:59 AM

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

Imar December 5th, 2009 10:45 AM

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

adamhw December 6th, 2009 09:02 AM

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

Imar December 6th, 2009 09:45 AM

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

adamhw December 7th, 2009 07:35 AM

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

Imar December 7th, 2009 09:18 AM

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

adamhw December 7th, 2009 10:07 AM

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

Imar December 7th, 2009 10:44 AM

It would help if you'd say what error you're getting exactly.....

Imar

adamhw December 7th, 2009 11:19 AM

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: &quot;&lt;link&gt;http://www.bio&quot;]'</font>

<p>
<font face="Arial" size=2>/blog2.asp</font><font face="Arial" size=2>, line 55</font>

thanks

Adam

Imar December 7th, 2009 11:58 AM

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


All times are GMT -4. The time now is 01:40 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.