dim strret
if isnull(fstrsource) then
fstrsource = ""
end if
strret = replace ( fstrsource , "&" , "&" )
strret = replace ( strret , "<" , "<" )
strret = replace ( strret , ">" , ">" )
strret = replace ( strret , """" , """ )
strret = replace ( strret , "" , "'" )
replacechar = strret
end function
function rsttoxml (frstrst, fstrrstname)
dim strspace space string behand of element
dim intlevel level of the element
dim strxml the return string(xml string)
dim intrstfield
dim strshortdate
document level
intlevel = 0
strspace = space (intlevel * 2)
if len(fstrrstname)>0 then
strxml=strspace & "<" & fstrrstname & ">" & vbcr
intlevel = intlevel + 1
strspace = space(intlevel*2)
end if
if frstrst.eof then
strxml = strxml&strspace & "<record"
for ncount=0 to frstrst.fields.count-1
strxml = strxml & space(1)&frstrst.fields(ncount).name&"="
next
strxml = strxml & "/>" &vbcr
if len(fstrrstname)>0 then
strxml=strxml&strspace & "</" & fstrrstname & ">" & vbcr
end if
rsttoxml=strxml
exit function
end if
now move in one level
intlevel = intlevel + 1
strspace = space (intlevel * 2)
loop through the records
dim strtemp
frstrst.movefirst
do while not frstrst.eof
strtemp = ""
loop through the fields
strxml = strxml & strspace & "<record"
for each objfield in frstrst.fields
set objfield = frstrst.fields(intrstfield)
strtemp = strtemp & space (1) & objfield.name & "="
strtemp = strtemp & """" & replacechar(objfield.value) & """"
end if
next
strxml = strxml & "<record "&strtemp& "/>" & vbcr
frstrst.movenext
loop
intlevel=intlevel-1
strspace=space(intlevel * 2)
if len(fstrrstname)>0 then
strxml = strxml & strspace & "</" & fstrrstname & ">" & vbcr
end if
rsttoxml = strxml
end function
getinfo.asp
========================================
<?xml version="1.0" encoding="gb2312"?>
<root>
<%
set conn = server.createobject("adodb.connection")
conn.open "filedsn=test.dsn"
set facultyrst = conn.execute("select * from faculty")
do while not facultyrst.eof
strfaculty = facultyrst("name")
set classrst = conn.execute("select count(id) as classcount from recruitclass where recruityear=" + cstr(year(now)) + " and faculty=" + strfaculty + "")
set malerst = conn.execute("select count(id) as malecount from newstudent where recruityear=" + cstr(year(now)) + " and faculty=" + strfaculty + " and gender=男")
set femalerst = conn.execute("select count(id) as femalecount from newstudent where recruityear=" + cstr(year(now)) + " and faculty=" + strfaculty + " and gender=女")
%>
<newstudent faculty="<%=strfaculty%>" class="<%=classrst("classcount")%>" male="<%=malerst("malecount")%>" female="<%=femalerst("femalecount")%>"/>
<%
facultyrst.movenext
loop
%>
</root>
<%
dim strconn, strsql, rs, n, sfilename
change the server name, if it is remote, change the uid and pwd to your own
strconn = "provider=sqloledb;server=localhost;database=pubs;uid=sa;pwd=;"
strsql = "select * from employee"
set rs = server.createobject("adodb.recordset")
rs.open strsql, strconn, 1, 1
sfilename = "c:\temp\employee.xml"
rs.save sfilename, 1
rs.close
set rs =nothing
%>
or
<%
response.contenttype = "text/xml"
dim strconn, strsql, rs, n, sfilename
change the server name, if it is remote, change the uid and pwd to your own
strconn = "provider=sqloledb;server=localhost;database=pubs;uid=sa;pwd=;"
strsql = "select * from employee"
set rs = server.createobject("adodb.recordset")
rs.open strsql, strconn, 1, 1
sfilename = "c:\temp\employee.xml"
rs.save response, 1
rs.close
set rs =nothing
%>
文章整理:站长天空 网址:http://www.z6688.com/
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




