Crear un archivo XML con ASP clasico

Código ASP clásico

Crear un archivo XML desde ASP clásico puede ser muy útil si se desea intercambiar información entre diversas plataformas.

A continuación se muetra la forma en que se obtienen registros de un base de datos y se convierten en un archivo XML:

<title> XML from Access)</title>
<body bgcolor="#FFFFFF">
' Name of the access db being queried

' Connection string to the access db
cn="DRIVER={Microsoft Access Driver (*.mdb)};"
cn=cn & "DBQ=" & server.mappath(accessdb)

' Create a server recordset object
Set rs = Server.CreateObject("ADODB.Recordset")

' Query the states table from the state_info db
sql = "select state,statename,capital,year,order from states order by states.order "

' Execute the sql
rs.Open sql, cn

' Move to the first record

' Name for the ouput document
file_being_created= "states.xml"

' create a file system object
set fso = createobject("scripting.filesystemobject")

' create the text file - true will overwrite any previous files
' Writes the db output to a .xml file in the same directory
Set act = fso.CreateTextFile(server.mappath(file_being_created), true)

' All non repetitive xml on top goes here
act.WriteLine("<?xml version=""1.0""?>")

'Loop to output all the query results to the xml document
do while not rs.eof

' counter to give each record a sequential listing

act.WriteLine("<state id="""& counter &""">")
act.WriteLine("<state_abbrev>" & rs("state") & "</state_abbrev>" )
act.WriteLine("<state_name>" & rs("statename") & "</state_name>" )
act.WriteLine("<state_capital>" & rs("capital") & "</state_capital>")
act.WriteLine("<year_admitted>"& rs("year") & "</year_admitted>")
act.WriteLine("<order_admitted>"& rs("order") & "</order_admitted>")

' move to the next record

' All non repetitive xml on bottom goes here

' close the object (xml)

' Writes a link to the newly created xml document in the browser
response.write "<a href='states.xml'>States</a> (.xml) has been created <br>"
response.write "on " & now() & "<br>"

tags: crear xml en asp clasico, generar xml desde asp clasico, asp xml, asp xmldatasource, asp xml control, classic asp xml to json, asp classic crear xml, asp clasico ejemplos, asp classic