频道直达 - 学院 - 下载 - 交易 - 特效 - 字库 - 手册 -排名-工具- 繁體
网页教学网站开发 设为首页
加入收藏
联系我们
建站搜索: 常用广告代码   用户注册 | 用户登陆
您当前的位置:中国建站之家 -> 网站开发设计技术教程 -> asp教程 -> 如何用Asp动态生成xml文件

如何用Asp动态生成xml文件

作者:未知  来源:转载  发布时间:2005-9-16 0:52:48  发布人:acx

减小字体 增大字体

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


将本文收藏到QQ书签与更多好友分享
[打 印]
[] [返回上一页] [收 藏]
∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论...]
精彩推荐
热门文章
· 注册码大全二
· 注册码大全四
· 注册码大全一
· 要10G免费网络硬盘的请进..
· 通过google 赶快来赚美金..
· 注册码大全十
· 头像-qq头像(qq新头像)4..
· 让你轻松架设FTP服务器1..
· 注册码大全三
· 梦幻背景图片7
· 卡通动物图片6
· 网页制作素材-按钮素材2..
· 让你轻松架设FTP服务器5..
· 风景图片8
· 注册码大全九
· 让你轻松架设FTP服务器2..
关注此文读者还看过
· MySQL 查询中的分页思路..
· 创建用户定义的 SQL Ser..
· 给任何控件添加链接功能..
· 兰色字母
· 用ADO STREAM做的无组件..
· DataGrid Web控件深度历..
· 学网页设计与网页制作,..
· 金山CEO雷军致员工上市公..
· 关于Global.asa文件的深..
· Photoshop CS2 新功能体..
· 闭合浮动元素让CSS代码更..
· Flash MX 编程深层次应用..
· 在WIN平台上让你的 Apac..
· 用asp怎样编写文档搜索页..
· HTML结构化:实践DIV+C..
· Photoshop滤镜的选择技巧..
相关文章
· 在不支持FSO的服务器上使用..
· 在网页XHTML文件中引入CSS样..
· Java对象与XML文件之间相互..
· 制作网页时是先准备CSS文件..
· 超长文章内容如何进行分页并..
· 注意:HTML文件也能格式化硬..
· XMLTextReader和XmlDocumen..
· XMLTextReader和XmlDocumen..
· XMLTextReader和XmlDocumen..
· ASP生成WML文件源代码样本
· ASP生成静态Html文件技术杂..
· ASP生成静态Html文件技术杂..
· 实用HTML文件的增强标记
· 实用HTML文件的增强标记
· 如何用asp把sql server數據..
· 大家看看如何用asp操作Orac..
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 人才招聘
网站合作、内容监督、商务咨询:QQ: 9576619
Copyright ? 2005--2008 中国建站之家版权所有
粤ICP备05092265号