asp下用fso和ado.stream写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=""//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")
上一篇: 应用SVM对MNIST数据集进行分类