Revision: 29903
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at August 5, 2010 01:24 by mchadwick
Initial Code
ASP Manual: This version loops over a query. Edit the Query and XML node names to match your needs. <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <% Dim MM_conn_STRING MM_conn_STRING = "dsn=image_gallery;uid=xxxx;pwd=xxxx" %> <% Dim rsImages Dim rsImages_cmd Dim rsImages_numRows ' Query the database and get all the records from the Images table Set rsImages_cmd = Server.CreateObject ("ADODB.Command") rsImages_cmd.ActiveConnection = MM_conn_STRING rsImages_cmd.CommandText = "SELECT ID, AlbumName, ImagePath, ImageDescription, UploadDate FROM images" rsImages_cmd.Prepared = true Set rsImages = rsImages_cmd.Execute ' Send the headers Response.ContentType = "text/xml" Response.AddHeader "Pragma", "public" Response.AddHeader "Cache-control", "private" Response.AddHeader "Expires", "-1" %><?xml version="1.0" encoding="utf-8"?> <images> <% While (NOT rsImages.EOF) %> <image> <ID><%=(rsImages.Fields.Item("ID").Value)%></ID> <album><![CDATA[<%=(rsImages.Fields.Item("AlbumName").Value)%>]]></album> <path><![CDATA[<%=(rsImages.Fields.Item("ImagePath").Value)%>]]></path> <description><![CDATA[<%=(rsImages.Fields.Item("ImageDescription").Value)%>]]></description> <date><![CDATA[<%=(rsImages.Fields.Item("UploadDate").Value)%>]]></date> </image> <% rsImages.MoveNext() Wend %> </images> <% rsImages.Close() Set rsImages = Nothing %> Automatic: This version evaluates the query and automatically builds the nodes from the column names. <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <% Dim MM_conn_STRING MM_conn_STRING = "dsn=image_gallery;uid=xxxx;pwd=xxxx" %> <% Dim rsAll Dim rsAll_cmd Dim rsAll_numRows ' Query the database and get all the records from the Images table Set rsAll_cmd = Server.CreateObject ("ADODB.Command") rsAll_cmd.ActiveConnection = MM_conn_STRING rsAll_cmd.CommandText = "SELECT * FROM Images" rsAll_cmd.Prepared = true Set rsAll = rsAll_cmd.Execute ' Send the headers Response.ContentType = "text/xml" Response.AddHeader "Pragma", "public" Response.AddHeader "Cache-control", "private" Response.AddHeader "Expires", "-1" %><?xml version="1.0" encoding="utf-8"?> <root> <% While (NOT rsAll.EOF) %> <row> <% For each field in rsAll.Fields column = field.name %> <<%=column%>><![CDATA[<%=(rsAll.Fields.Item(column).Value)%>]]></<%=column%>> <% Next %> </row> <% rsAll.MoveNext() Wend %> </root> <% rsAll.Close() Set rsAll = Nothing %>
Initial URL
Initial Description
Initial Title
Convert database queries to xml using asp
Initial Tags
xml, ASP, convert
Initial Language
ASP