Listing F
Function fnSQLtoXML(sFilePath, sSQL, sElementName) Dim sRetVal, oConn, oRS Set oConn = Server.CreateObject("ADODB.Connection") Set oRS = Server.CreateObject("ADODB.Recordset") If sFilePath = "" Then sRetVal = "No Database File" ElseIf sSQL = "" Then sRetVal = "No SQL Statement" ElseIf sElementName = "" Then sRetVal = "No Element Name" Else sRetVal = vbCrLf & "<" & sElementName & ">" On Error Resume Next oConn.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(sFilePath)) If Err.Number = 0 Then Set oRS = oConn.Execute(sSQL) If Err.Number = 0 Then Do Until oRS.EOF For Each Field in oRS.Fields sRetVal = sRetVal & vbCrLf & "<" & Field.name & " value='" & Field.value & "'>" sRetVal = sRetVal & "</" & Field.name & ">" Next oRS.MoveNext Loop Else sRetVal = sRetVal & vbCrLf & "<error value='" & Err.Description & "'></error>" End If oConn.Close Else sRetVal = sRetVal & vbCrLf & "<error value='" & Err.Description & "'></error>" End If sRetVal = sRetVal & vbCrLf & "</" & sElementName & ">" End If Set oRS = Nothing Set oConn = Nothing fnSQLtoXML = sRetVal End Function