Xml Recordset Server2Client by Bob Barrows

Click here to generate a table from the data in the recordset:


Code:<!--#include virtual="/testsite/global_include.asp" --> <% dim sXML, cn, rs, sSQL,arData,arNames,xmldoc 'Insert your database server details: set cn = server.CreateObject("ADODB.Connection") cn.Open Application("ConnectionString") sSQL = "Select CompanyName,ContactName,City FROM Northwind..Suppliers" set rs = cn.Execute(sSQL,,adCmdText) set xmldoc = Server.CreateObject("msxml2.domdocument") rs.save xmldoc, adPersistXML rs.Close set rs=nothing cn.Close Set cn = Nothing 'the following line eliminates whitespace and handles 'literal quotes sXML = replace(replace(xmldoc.xml,vbCrLf,""),"""","""""") set xmldoc = nothing %> <HTML> <HEAD> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Xml Recordset Server2Client by Bob Barrows</title> <link rel="stylesheet" href="/Templates/style.css" type="text/css" /> <SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript> <!-- dim rsSuppliers Sub window_onload dim xmldoc set xmldoc = createobject("Microsoft.XMLDOM") xmldoc.loadxml "<%=sXML%>" set rsSuppliers = CreateObject("ADODB.Recordset") rsSuppliers.Open xmldoc 'Proof that you have an ADO recordset: msgbox "Recordset contains " & rsSuppliers.RecordCount & _ " records" End Sub Sub window_onunload on error resume next rsSuppliers.Close set rsSuppliers = nothing End Sub Sub button1_onclick dim sHTML if not rsSuppliers.EOF then sHTML=rsSuppliers.GetString(2,,"</td><td>","</tr><tr><td>") sHTML = left(sHTML,len(sHTML) - 8) sHTML = "<table border=1><tr><td>" & sHTML & "</table>" button1.insertAdjacentHTML "afterend", sHTML end if End Sub --> </SCRIPT> </HEAD> <BODY> <h3>Xml Recordset Server2Client by Bob Barrows</h3> Click here to generate a table from the data in the recordset: <INPUT type="button" id=button1 name=button1 style="WIDTH: 15px; HEIGHT: 15px"> <br /><br /><pre> <% displayAspFile Server.MapPath("xml.recordset.server2client.asp") %> </pre> </BODY> </HTML>