日期:2014-05-17  浏览次数:21099 次

asp如何生成utf-8格式的xml文件??
代码如下
<!--   #include   file   =   "xmlconn.asp "   -->
<%
opendatabase
xmlfile=server.mappath( "test.xml ")  
Set   fso   =   CreateObject( "Scripting.FileSystemObject ")  
Set   MyFile   =   fso.CreateTextFile(xmlfile,True)  
MyFile.WriteLine( " <?xml   version= " "1.0 " "   encoding= " "utf-8 " "?> ")  
MyFile.WriteLine( " <document> ")  
MyFile.WriteLine( " <webSite> ")
MyFile.WriteLine( "http://www.test.com ")
MyFile.WriteLine( " </webSite> ")  
.....

当我节点中有中文时,运行这个xml文件会报错,好象是编码不对,我找了资料,网上说是用记事本打将,再另存为成utf-8格式的,我这个是在服务器上的,1小时生成一次,有很多XML文件,我一个个去另存为不太现实,如何才能生成utf-8格式的xml文件

------解决方案--------------------
opendatabase
xmlfile=server.mappath( "test.xml ")
Set MyFile = Server.CreateObject( "ADODB.Stream ")
MyFile.Type = adTypeText
MyFile.Charset = "utf-8 "
MyFile.Open
MyFile.WriteText " <?xml version= " "1.0 " " encoding= " "utf-8 " "?> ", adWriteLine
MyFile.WriteText " <document> ", adWriteLine
MyFile.WriteText " <webSite> ", adWriteLine
MyFile.WriteText "http://www.test.com ", adWriteLine
MyFile.WriteText " </webSite> ", adWriteLine
.....
MyFile.SaveToFile xmlfile, adSaveCreateOverWrite
MyFile.Close
Set MyFile = Nothing