ASP query XML by keyword
'------------------------------------------------------
' Read 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 the information to 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=" "cloud-dwelling community" "/>"
Msg=msg & "</bcaster>"
Call Writetxtfile (msg, "X1.xml")
The FSO defaults to ASCII encoding because you must use the UTF-8 encoding to write the file with Ado.stream, as 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=" "cloud-dwelling community" "/>"
Msg=msg & "</bcaster>"
Call CreateFile (msg, "X1.xml")