Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 5th, 2009, 07:59 AM
Authorized User
Points: 405, Level: 7
Points: 405, Level: 7 Points: 405, Level: 7 Points: 405, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2009
Posts: 85
Thanks: 16
Thanked 0 Times in 0 Posts
Default 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
  #2 (permalink)  
Old December 5th, 2009, 10:45 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #3 (permalink)  
Old December 6th, 2009, 09:02 AM
Authorized User
Points: 405, Level: 7
Points: 405, Level: 7 Points: 405, Level: 7 Points: 405, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2009
Posts: 85
Thanks: 16
Thanked 0 Times in 0 Posts
Default 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
  #4 (permalink)  
Old December 6th, 2009, 09:45 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #5 (permalink)  
Old December 7th, 2009, 07:35 AM
Authorized User
Points: 405, Level: 7
Points: 405, Level: 7 Points: 405, Level: 7 Points: 405, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2009
Posts: 85
Thanks: 16
Thanked 0 Times in 0 Posts
Default 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
  #6 (permalink)  
Old December 7th, 2009, 09:18 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #7 (permalink)  
Old December 7th, 2009, 10:07 AM
Authorized User
Points: 405, Level: 7
Points: 405, Level: 7 Points: 405, Level: 7 Points: 405, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2009
Posts: 85
Thanks: 16
Thanked 0 Times in 0 Posts
Default 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
  #8 (permalink)  
Old December 7th, 2009, 10:44 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #9 (permalink)  
Old December 7th, 2009, 11:19 AM
Authorized User
Points: 405, Level: 7
Points: 405, Level: 7 Points: 405, Level: 7 Points: 405, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2009
Posts: 85
Thanks: 16
Thanked 0 Times in 0 Posts
Default 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
  #10 (permalink)  
Old December 7th, 2009, 11:58 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!




Similar Threads
Thread Thread Starter Forum Replies Last Post
Using ASP classic filesystem object to retrieve a xml file turns characters into Chin grotgod Classic ASP Basics 5 March 8th, 2009 03:07 PM
Converting Classic Asp to Asp.Net 2.0 vikaspatyal ASP.NET 2.0 Professional 2 October 7th, 2007 06:33 PM
Converting Source Xml into Target Xml Using XSL. alapati.sasi XSLT 3 May 14th, 2007 10:54 AM
Converting XML to XML (making element mandatory) boondocksaint20 XSLT 8 April 28th, 2006 10:54 AM
increase caching size in Classic ASP page crmpicco Classic ASP XML 0 April 4th, 2006 11:28 AM





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