<%@ LANGUAGE="VBScript" %>
<%
'**************************************************************************
'* Given a city and state, returns an XML file containing a list of valid
'* ZIP codes.
'**************************************************************************
'Buffer output.
Response.Buffer = true
'Set response Content-type header.
Response.ContentType = "text/xml"
'Start the XML document.
Response.Write("<?xml version=""1.0"" encoding=""UTF-8""?>" & vbCrLF)
'Open the database connection.
dbq = Server.MapPath("data/ZipCodes.mdb")
set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DBQ=" & dbq & ";DRIVER={Microsoft Access Driver (*.mdb)};"
'Look up the city and state.
sql = "select * from ZipCodes" _
& " where City = '" & Request("city") & "' and State = '" & Request("state") & "'" _
& " order by ZipCode"
set rs = conn.Execute(sql)
'Create the root XML tag.
if not rs.BOF and not rs.EOF then
'Add the city and state as attributes.
Response.Write("<zipCodes city=""" & rs.Fields("City").Value & """ state=""" & rs.Fields("State").Value & """>" & vbCrLf)
else
Response.Write("<zipCodes>" & vbCrLf)
end if
'Add an XML tag for each matching Zip code.
do while not rs.EOF
Response.Write(vbTab & "<zipCode>" & rs.Fields("ZipCode") & "</zipCode>" & vbCrLF)
rs.MoveNext
loop
Response.Write("</zipCodes>")
%>