FileWrite() 写 XML UTF-8编码问题
如题,用FileWrite()写XML的时候出现问题,写成的文件默认的编码格式为 ANSI,另一边的软件不解析,需要改成UTF-8的编码格式,求各位大虾指导~~~
Test代码如下:
string ls_filename integer ll_filetype ls_filename='D:\SFDA\InData\Bussiness\PurchaseWareHouseIn_'+'11110001'+'.xml' ll_filetype=FileOpen(ls_filename, LineMode!, Write!, LockWrite!, Append!) FileWrite(ll_filetype,'<?xml version="1.0" encoding="utf-8"?>') FileWrite(ll_filetype,'<Document>') FileWrite(ll_filetype,'<Events>') FileWrite(ll_filetype,'<Event Name="PurchaseWareHouseIn" MainAction="WareHouseIn">') FileWrite(ll_filetype,'<DataField>') FileWrite(ll_filetype,'<Data Code="88136640000856829580" Actor="1111" ActDate="2011-10-27 13:54:50" CorpOrderID="11110098" FromCorpID="" ToCorpID="" OwnerID="" />') FileWrite(ll_filetype,'</DataField>') FileWrite(ll_filetype,'</Event>') FileWrite(ll_filetype,'</Events>') FileWrite(ll_filetype,'</Document>') fileclose(ll_filetype)
string ls_filename, ls_content //内容ls_filename='D:\SFDA\InData\Bussiness\PurchaseWareHouseIn_'+'11110001'+'.xml'oleObject ADODB ADODB = CREATE OLEObject if ADODB.ConnectToNewObject("ADODB.Stream") <> 0 then messagebox('提示', '无法连接【ADODB.Stream】!无法写文件!') return -1 end if ADODB.Mode =3 //具有读/写权限 ADODB.Open() ADODB.Position = 0 ADODB.type = 2ADODB.charset = "UTF-8"ls_content = '<?xml version="1.0" encoding="utf-8"?>'+& '~r~n<Document>'+& '~r~n<Events>'+& '~r~n<Event Name="PurchaseWareHouseIn" MainAction="WareHouseIn">'+& '~r~n<Data Code="88136640000856829580" Actor="1111" ActDate="2011-10-27 13:54:50" CorpOrderID="11110098" FromCorpID="" ToCorpID="" OwnerID="" />'+& '~r~n</DataField>'+& '~r~n</Event>'+& '~r~n</Events>'+& '~r~n</Document>'ADODB.WriteText(ls_content) try ADODB.savetofile(ls_filename, 2) catch (oleruntimeerror er) messagebox('提示', '无法写文件到【' + ls_filename + '】!~r~n可能的原因有:①文件路径不存在,②磁盘空间不够') end try //清空缓冲区数据 ADODB.flush() //关闭流 ADODB.Close() destroy ADODB