当前位置: 移动技术网 > IT编程>开发语言>Asp > asp下用fso和ado.stream写xml文件的方法

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

2017年12月12日  | 移动技术网IT编程  | 我要评论

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=""//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=""//www.jb51.net"" itemtitle=""移动技术网""/>"
msg=msg & "</bcaster>"
call createfile(msg,"x1.xml")

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网