|
kt -> RE: ASP to XML (7/31/2005 18:38:30)
|
Hi Iain Thanks for the reply. I think I've figured it out, but in a totally different way - with the help of http://www.codeave.com/asp/code.asp?u_log=149. Here's what I'm using now:
<%
Set cn = Server.CreateObject("ADODB.Connection")
cn.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("../fpdb/jobs.mdb")
Set rs = Server.CreateObject("ADODB.Recordset")
Set rs = cn.Execute("SELECT ID, country, city, title, dateposted FROM jobs ORDER BY dateposted DESC")
rs.MoveFirst
file_being_created= "jobs12.xml"
set fso = createobject("scripting.filesystemobject")
Set act = fso.CreateTextFile(server.mappath(file_being_created), true)
act.WriteLine("<?xml version=""1.0""?>")
act.WriteLine("<rss version=""2.0"">")
act.WriteLine("<channel>")
act.WriteLine("<title>Latest jobs from eslbase.com</title>")
act.WriteLine("<description>Latest jobs</description>")
act.WriteLine("<link>http://www.eslbase.com/tefl_jobs.asp</link>")
do while not rs.eof
counter=counter+1
act.WriteLine("<item>")
act.WriteLine("<title>" & rs("country") & "</title>" )
act.WriteLine("<description>" & rs("title") & "</description>")
act.WriteLine("<link>http://www.eslbase.com/tefl_job_details?ID=</link>")
act.WriteLine("</item>")
rs.movenext
loop
act.WriteLine("</channel>")
act.WriteLine("</rss>")
act.close
response.write "<a href='jobs12.xml'>Jobs</a> (.xml) has been created <br>"
response.write "on " & now() & "<br>"
%> The output is this RSS page: <?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>Latest jobs from eslbase.com</title>
<description>Latest jobs</description>
<link>http://www.eslbase.com/tefl_jobs.asp</link>
<item>
<title>Oman</title>
<description>REQUIRED ENGLISH TEACHERS TO OMAN</description>
<link>http://www.eslbase.com/tefl_job_details?ID=</link>
</item>
<item>
<title>China</title>
<description>Working In a Famous Training Center 1000USD/MONTH</description>
<link>http://www.eslbase.com/tefl_job_details?ID=</link>
</item>
<item>
<title>China</title>
<description>International Primary School Teacher</description>
<link>http://www.eslbase.com/tefl_job_details?ID=</link>
</item>
.....Items go on until the end here
</channel>
</rss> Basic RSS but works well for what I need... A couple of questions you (or anyone else!!) may be able to help me out with though... 1 How can I change this line on the asp page... Set rs = cn.Execute("SELECT ID, country, city, title, dateposted FROM jobs ORDER BY dateposted DESC") ...to retun only, say, 10 results? (i know there's a "TOP" command, but can't seem to make it work...) 2 On this line on the asp page... act.WriteLine("<link>http://www.eslbase.com/tefl_job_details?ID=</link>") ...I want it to say .../tefl_job_details?ID=rs("ID") (i.e. the ID called in the SQL) I've played around with it but can't seem to get the syntax right. Thanks again for the help kt EDIT: OK, both problems solved - it was late at night, wasn't thinking straight!! 1 Set rs = cn.Execute("SELECT TOP 10 ID, country, city, title, dateposted FROM jobs ORDER BY dateposted DESC") ...was sure I'd tried this before. 2 act.WriteLine("<link>" & "http://www.eslbase.com/tefl_job_details.asp?ID=" & rs("ID") & "</link>")
|
|
|
|