用fso\用ado.stream写xml文件
003
用asp来生成xml文件,一开始我用fso,只用了写,同时把读文件的办法也给大家,代码如下:
'------------------------------------------------------
'读取文件 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.goodtext.org"" 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.goodtext.org"" itemtitle=""文本文本""/>"
msg=msg & "</bcaster>"
call CreateFile(msg,"x1.xml")
Tags:函数
操作文本的精典Function函数ASP+FSO (2008-7-22 10:23:7)
数据操作函数 (2008-6-25 7:49:46)
几种过滤HTML代码的应用 (2008-4-27 10:33:17)
ASP防注入危险字符代码 (2008-4-10 18:56:43)
GOODTEXT.ORG留言本 V 1.0 (2008-3-30 22:3:32)
留言管理部分代码 留言本制作过程(3) (2008-3-30 21:5:59)
显示留言部分代码 GOODTEXT.ORG留言本制作过程(2) (2008-3-30 20:57:14)
数据库结构设计与链接 GOODTEXT.ORG留言本制作过程(1) (2008-3-27 18:58:58)
CSS样式控制网页背景(背景颜色和颜色图片) (2008-3-22 12:44:4)
asp分页做成一个函数 可重复调用 (2008-3-9 9:15:50)