ASP keyword-based XML query
'------------------------------------------------------
'Read the file 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
'------------------------------------------------------------
'Write information into the file
'------------------------------------------------------------
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
'-----------------------------------------------------------
'Generate XML file
'-----------------------------------------------------------
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 is ascii by default, because it must be UTF-8 encoded and ADO. stream is used to write this file,CodeAs follows:
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 ")