VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Save ADO recorset to XML file and open the XML file with VBscript

by gabio (9 Submissions)
Category: Active Server Pages
Compatability: ASP (Active Server Pages)
Difficulty: Unknown Difficulty
Originally Published: Mon 22nd July 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

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



 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
%>

Download this snippet    Add to My Saved Code

Save ADO recorset to XML file and open the XML file with VBscript Comments

No comments have been posted about Save ADO recorset to XML file and open the XML file with VBscript. Why not be the first to post a comment about Save ADO recorset to XML file and open the XML file with VBscript.

Post your comment

Subject:
Message:
0/1000 characters