上一篇 | 这是最后一篇日志下一篇
asp 订阅所有【asp】的日志

asp FSO生成XML乱码解决

修改网站时遇到个问题,生成xml乱码,xml文档里声明的是utf-8的,其实生成的是ASCII,应该是Unicode编码才不会出问题。

Set f = fso.CreateTextFile(Server.MapPath(".")&"\china-thinking.htm",true)一句代码中CreateTextFile就是FileSystem对象的其中一个属性,表示新建文件他后面是有参数的

CreateTextFile(FileName[,Overwrite[,Unicode]]) 其中中括号〔〕括起来的部分表示可选参数,它是有缺省值的,

FileName表示新建文件的名字,

OverWrite表示如果新建文件存在此方法是否覆盖已存在的文件,它的值为true或者false,缺省值为False表示不覆盖。

Unicode的值也是true或者false,他的缺省值也是False表示创建的字符集为ASCII,否则创建的字符集则为Unicode。

附上今天修改的asp生成xml二级菜单代码:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Conn.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>生成xml</title>
</head>
<body>
<%


set res=server.createobject("adodb.recordset")
strsql="select * from product_big"
res.open strsql,conn,1,1



'生成xml
xmlfile=server.mappath("../dwnTree.xml")
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile(xmlfile,True,True)
MyFile.WriteLine("<?xml version=""1.0"" encoding=""utf-8""?>")
MyFile.WriteLine("<item>")
do while not res.eof  
    MyFile.WriteLine("<item caption="""&res("bigclassname")&""" unfolded="""">")
    
set rs=server.CreateObject("adodb.recordset")
    sql="select * from product_small where bigclassname='"&res("bigclassname")&"' "
    rs.open sql,conn,1,1
    do while not rs.eof
    
    
set rsd=server.CreateObject("adodb.recordset")
    sqll="select top 1 id from Products where smallclassname='"&rs("SmallClassName")&"' order by id asc "
    rsd.open sqll,conn,1,1
    if not(rs.bof and rs.eof) then
    MyFile.WriteLine("<item caption="""&rs("smallclassname")&"""  url=""products_show.asp?id="&rsd("id")&""" target=""_parent""></item>")
    else
    
    MyFile.WriteLine("<item caption="""&rs("smallclassname")&"""  url=""products_show.asp?id="&rs("id")&""" target=""_parent""></item>")
end if
rsd.close
Set rsd = Nothing
    
    rs.movenext
        loop
    
rs.close
Set rs = Nothing

MyFile.WriteLine("</item>")
res.movenext
loop
res.close
Set res = Nothing
conn.close
set conn=Nothing
MyFile.WriteLine("</item>")
MyFile.Close
%>
</body>
</html>



[本日志由 wyc 于 2010-05-12 11:52 AM 编辑]
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
相关日志:
评论: 0 | 引用: 0 | 查看次数: 167
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 关闭 | [img]标签 开启