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.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=""http://www.jb51.net"" itemtitle=""指令碼之家""/>"
msg=msg & "</bcaster>"
call CreateFile(msg,"x1.xml")