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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-03-17 我要评论
想了解asp下用fso和ado.stream写xml文件的方法的相关内容吗,在本文为您仔细讲解asp来生成xml的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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.qb5200.com"" 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.qb5200.com"" itemtitle=""""/>"
msg=msg & "</bcaster>"
call CreateFile(msg,"x1.xml")

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们