公告
广告载入中...
asp FSO生成XML乱码解决
作者:wyc 日期:2010-05-12
修改网站时遇到个问题,生成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>
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>
评论: 0 | 引用: 0 | 查看次数: 167
发表评论
上一篇
下一篇


文章来自:
Tags:
相关日志:







