Contents of xmls2ke1.asp:
<html> <head> <SCRIPT language="javascript"> var rc=0; function ol() { var root=data_island.documentElement; if (data_island.parseError !=0) alert(data_island.parseError.reason); xml_string="<p>"; for (i=0;i<root.childNodes.length-1;i++) { rc=rc+1 xml_string=xml_string+"<br><"+root.childNodes.item(i).nodeName+" "; for(j=0;j<root.childNodes.item(i).attributes.length;j++) { xml_string=xml_string+" "+root.childNodes(i).attributes.item(j).nodeName; xml_string=xml_string+"="+String.fromCharCode(34); xml_string=xml_string+root.childNodes(i).attributes.item(j).text+String.fromCharCode(34); } xml_string=xml_string+"/>" } xout.innerHTML = xml_string+"<p>Number of rows="+rc.toString(); } </SCRIPT> </head> <body bgcolor="#cccccc" onLoad="ol()"> <table border="1"> <tr><td valign='middle' bgcolor='#999999'><img src="captsm.gif"></td> <td valign='middle' bgcolor='#999999'><center><font color="#ffffff"><font face="Comic Sans MS"> <br> <b>A SIMPLE XML EXTRACT USING SQL SERVER 2000<br> "SELECT...FOR XML RAW"</b> <br> </td></tr></table> </center> <p> <font face="Comic Sans MS" size="2"> <p> The SQL connection string is ="SELECT * from glmaster <b>FOR XML RAW</b>" <p> Note: The connection is OLEDB <u>NOT</u> DSN. <p> MS SQL Server 2000 returns 1 tag per table row (cleverly named <b>row</b>) with each column value as an attribute. <br>This tag name not cannot be modified. <p> The XML is returned to the client as an XML data island and rolled out through javascript using the XML DOM. <p> Click "VIEW", then "SOURCE" to see the XML data island and the javascript XMLDOM rollout Execution begins... <p> <form name="xmltest"> <XML id="data_island"><outsidetag> <% set cn=Server.CreateObject("ADODB.Connection") cn.open "Provider=SQLOLEDB; Data Source=AUCKLAND; Initial Catalog=gl001; User ID =gl001; Password=11111;" set cm=Server.CreateObject("ADODB.Command") set cs=CreateObject("ADODB.Stream") set cm.ActiveConnection = cn cm.CommandType = 1 '*** Text cm.CommandText="SELECT * from glmaster FOR XML RAW" cs.mode=1 cs.Type=2 cs.open cm.Properties("Output Stream").value = cs cm.execute,,1024 Response.Write cs.ReadText cn.close set cn=nothing set cm=nothing set cs=nothing %>"> </outsidetag></XML> <div id="xout"></DIV> <p> Click <a href="bdoc.asp?fl=x2"> here</a> for the source code </body> </html>
***** end of file *** printed: 86 lines on: 11/23/2009 6:11:25 AM