您的位置:首页网页设计ASP实例 → 如何用Asp动态生成xml文件

如何用Asp动态生成xml文件

时间:2004/11/7 3:02:00来源:本站整理作者:蓝点我要评论(0)

Function ReplaceChar ( FstrSource )
  dim strRet
  if IsNull(FstrSource) then
    FstrSource = ""
  end if
  strRet = Replace ( FstrSource , "&" , "&" )
  strRet = Replace ( strRet , "<" , "&lt;" )
  strRet = Replace ( strRet , ">" , "&gt;" )
  strRet = Replace ( strRet , """" , "&quot;" )
  strRet = Replace ( strRet , "'" , "&apos;" )
  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 & "    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 & "" & 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 & "      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 & "" & vbCR
      FrstRst.MoveNext
  loop
 
  intLevel=intLevel-1
  strSpace=space(intLevel * 2)


  if Len(FstrRstName)>0 then
    strXML = strXML & strSpace & "" & vbCR
  end if


  RstToXML = strXML


end function


 


 


getInfo.asp
========================================


<%
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='女'")
%>
  " male="<%=maleRst("malecount")%>" female="<%=femaleRst("femalecount")%>"/>
 
<%
  facultyRst.MoveNext
loop
%>


 



<%
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
%>


 


相关阅读 Windows错误代码大全 Windows错误代码查询激活windows有什么用Mac QQ和Windows QQ聊天记录怎么合并 Mac QQ和Windows QQ聊天记录Windows 10自动更新怎么关闭 如何关闭Windows 10自动更新windows 10 rs4快速预览版17017下载错误问题Win10秋季创意者更新16291更新了什么 win10 16291更新内容windows10秋季创意者更新时间 windows10秋季创意者更新内容kb3150513补丁更新了什么 Windows 10补丁kb3150513是什么

文章评论
发表评论

热门文章 没有查询到任何记录。

最新文章 迅雷新手完全入门手册 asp下面javascript上传图片限制格式大小方法告诉大家网页弹出窗口应用总结ASP常见错误类型大全asp常见错误分析和解决办法

人气排行 总是弹出visual studio 实时调试器 三种解决SQLSERVER存储过程及调用详解Asp获取真实IP地址ASP中连接Mssql的几种方法一个简单好用的UBB编辑器(含代码)如何用Split将字符串转换为数组并获取数组下ASP防止表单重复提交的办法告诉你免费的简单聊天室源代码