Monday, December 05, 2005

asp to xml source code

This is the source code for returning and xml file with asp from an access
database.

I am sick of searching for it, and I do not want you to search any more for this
simple thing



set conn=Server.CreateObject("ADODB.Connection") conn.provider="Microsoft.Jet.OLEDB.4.0;"conn.open server.mappath("/fpdb/newsposter.mdb")
sql="select * from news ORDER BY news.ID DESC"set rs=Conn.Execute(sql)rs.MoveFirstfile_being_created= "output.xml"set fso = createobject("scripting.filesystemobject")
Set act = fso.CreateTextFile(server.mappath("/output.xml"), true)
act.WriteLine("")
act.WriteLine("")
act.WriteLine("")
do while not rs.eofcounter=counter+1act.WriteLine("")
act.WriteLine("")
act.WriteLine("" & rs("Short_desc") & "")
act.WriteLine("" & "http://yourwebsite.com/whats_new.asp?ID=" & rs("ID") & "")
act.WriteLine("")
rs.movenextloop
act.WriteLine("")
act.WriteLine("")
act.closeresponse.write "'/output.xml'>Output.xml (.xml) has been created
"response.write "on " & now() & ""


If you are a bit familiar you will work it out yourselves, else post comments. This code, should be entered in to a
texfile, and renamed to something.asp


The above webpage, when visited will return an xml document



If you just want an xml file to be written in a specific location use this code :


set conn=Server.CreateObject("ADODB.Connection") conn.provider="Microsoft.Jet.OLEDB.4.0;"conn.open server.mappath("/fpdb/newsposter.mdb")
sql="select * from news ORDER BY news.ID DESC"set rs=Conn.Execute(sql)rs.MoveFirstfile_being_created= "output.xml"set fso = createobject("scripting.filesystemobject")
Set act = fso.CreateTextFile(server.mappath("/output.xml"), true)
act.WriteLine("")
act.WriteLine("")
act.WriteLine("")
do while not rs.eofcounter=counter+1act.WriteLine("")
act.WriteLine("")
act.WriteLine("" & rs("Short_desc") & "")
act.WriteLine("" & "http://yourwebsite.com/whats_new.asp?ID=" & rs("ID") & "")
act.WriteLine("")
rs.movenextloop
act.WriteLine("")
act.WriteLine("")
act.closeresponse.write "'/output.xml'>Output.xml (.xml) has been created
"response.write "on " & now() & ""





always remember that this is asp code, and must have the asp tags before and after it (<% and %>)

so simple!
no copyrights, i will just be happy if you post comments and mention this page somewhere:)



0 Comments:

Post a Comment

<< Home