作家
登录

asp下用fso和ado.stream写xml文件的方法

作者: 来源:www.28hudong.com 2013-03-30 08:26:36 阅读 我要评论

asp按关键字查询XML的问题 '------------------------------------------------------ '读取文件 ReadTxtFile(FileName) '------------------------------------------------------ Function ReadTxtFile(FileName) Dim fso,f1,ts,FilePath FilePath=server.mappath(FileName) Set fso = CreateObject("Scripting.FileSystemObject") Set ts = fso.OpenTextFile(FilePath,1,1) ReadTxtFile = ts.ReadAll set ts=nothing set fso=nothing End Function '------------------------------------------------------------ '把信息写入文件 '------------------------------------------------------------ Function WriteTxtFile(Text,FileName) path=Server.MapPath(FileName) Set fso = CreateObject("Scripting.FileSystemObject") Set f1 = fso.CreateTextFile(path,true) f1.Write (Text) f1.Close End Function '----------------------------------------------------------- '生成xml文件 '----------------------------------------------------------- msg = "<?xml version=""1.0"" encoding=""utf-8""?>" msg=msg & "<bcaster>" msg=msg & "<item item_url=""http://www.jb51.net"" itemtitle=""脚本之家""/>" msg=msg & "</bcaster>" call WriteTxtFile(msg,"x1.xml") fso默认是ascII编码的,因为必须使用utf-8编码,用ado.stream来写这个文件,代码如下: Sub CreateFile(Text,FileName) Dim st Set st=Server.CreateObject("ADODB.Stream") st.Type=2 st.Mode=3 st.Charset="utf-8" st.Open() st.WriteText Text st.SaveToFile Server.MapPath(FileName),2 st.Close() Set st=Nothing End Sub msg = "<?xml version=""1.0"" encoding=""utf-8""?>" msg=msg & "<bcaster>" msg=msg & "<item item_url=""http://www.jb51.net"" itemtitle=""脚本之家""/>" msg=msg & "</bcaster>" call CreateFile(msg,"x1.xml")

  推荐阅读

  在Vista IIS 7 中用 vs2005 调试 Web 项目的注意事项

在Vista IIS 7 中用 vs2005 调试 Web 项目核心是要解决以下几个问题:1、Vista 自身在安全性方面的User Account Control (UAC) 2、安装必须的IIS7 组件。3、Vista 自带的IIS7 跟 IIS 6 在底层都发生了变化,我们如>>>详细阅读


本文标题:asp下用fso和ado.stream写xml文件的方法

地址:http://www.17bianji.com/kaifa2/ASP/32168.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)