用asp來產生xml文件,一開始我用fso,只用了寫,同時把讀文件的辦法也給大家
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=http://www.vevb.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=http://www.vevb.com itemtitle=腳本房子/>
msg=msg & </bcaster>
call CreateFile(msg,x1.xml)