手机
当前位置:查字典教程网 >编程开发 >ASP教程 >asp下用fso和ado.stream写xml文件的方法
asp下用fso和ado.stream写xml文件的方法
摘要:asp按关键字查询XML的问题'------------------------------------------------------...

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")

【asp下用fso和ado.stream写xml文件的方法】相关文章:

用asp实现的数据库中存取文件的代码

asp获取用户真实IP地址的方法

用ASP读取XML文件的具体方法与示例

用FSO获得图片文件的信息(大小,宽,高)

利用xmlhttp和adodb.stream加缓存技术下载远程Web文件

asp FSO 读写文件本文件实现代码

JScript中遍历Request表单参数集合的方法

ASP中利用execute实现动态包含文件的方法

asp 中常用的文件处理函数

图片的入库与读取的方法

精品推荐
分类导航