网络编程 
首页 > 网络编程 > 浏览文章

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

(编辑:jimmy 日期: 2024/9/22 浏览:3 次 )

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=""https://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=""https://www.jb51.net"" itemtitle=""""/>"
msg=msg & "</bcaster>"
call CreateFile(msg,"x1.xml")

上一篇:SQL"不能为新插入的行确定标识"错误的解决方法
下一篇:asp按关键字查询XML的代码
一句话新闻
Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 SiteMap