Save ADO recorset to XML file and open the XML file with VBscript
Save ADO recorset to XML file and open the XML file with VBscript
Rate Save ADO recorset to XML file and open the XML file with VBscript
(3(3 Vote))
set fs = server.CreateObject("Scripting.FileSystemObject")
' temp directory must exists with write permissions
tfolder = Request.ServerVariables("APPL_PHYSICAL_PATH") & "temp"
' temporary filename
filename = fs.GetTempName
filename = mid(filename,1,len(filename)-4)
finalfile = filename & ".xml" 'file used for redirect
filename = tfolder & "\" & filename & ".xml"
set textFile = fs.CreateTextFile (filename)
Dim rsTemp
set rsTemp = CreateObject("ADODB.Recordset")
set Con = Server.CreateObject("ADODB.Connection")
Con.Open "DSN=" & "myDSN" & ";uid=" & "sa"
set rsTemp.ActiveConnection = Con
'open recordset
rsTemp.Open ("select * from mytable")
Response.ContentType = "text/xml"
dim x
textFile.writeline "<?xml version=""1.0""?>"
textFile.writeline "<DATA>"
while not rsTemp.EOF
textFile.writeline "<RECORD>"
for x = 0 to rsTemp.Fields.Count - 1
TextFile.WriteLine "<" + rsTemp.Fields(x).Name + ">"
TextFile.WriteLine Server.HTMLEncode(trim(cstr(rsTemp.Fields(x).Value)))
'! atention to null fields! '
TextFile.WriteLine "</" + rsTemp.Fields(x).Name + ">"
next
TextFile.WriteLine "</RECORD>"
rsTemp.MoveNext
wend
TextFile.WriteLine "</DATA>"
set fs= nothing
rsTemp.Close
set rsTemp = nothing
con.Close
path = "temp/" & finalfile
Response.Redirect path
%>
Save ADO recorset to XML file and open the XML file with VBscript Comments
No comments yet — be the first to post one!
Post a Comment