xml乱码

blueonly 2005-06-23 11:52:47
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<%
'response.charset="utf-8"
dim o
set o=new clsXML
o.LoadFile("xml.htm")
Response.Write("<pre>" & server.htmlencode(o.XML) & "</pre>")
'o.SaveFile("xml2.htm")
dim n
'set n=o.GetNode("/Resource/Item[@name='resname2']")
dim nn,ln


set ln=o.Create("Item")
ln.appendchild(o.Create("Description"))
ln.appendchild(o.Create("Data"))
ln.childNodes(0).text="新建元素"
ln.childNodes(1).text="新建数据"

Response.Write("<pre>" & server.htmlencode(ln.XML) & "</pre>")

_______________________
Public Function LoadFile(sfile)
domXML.load(server.MapPath(sFile))
set oRootNode=domXML.documentElement
End Function
______________________
XML文件也是utf8的编码
<?xml version="1.0" encoding="utf-8" ?>
<Resource xmlns:b="http://www.blue1018.net/resource">
<Item name="resname" >
<Description>
资源描述
</Description>
<Data>
数据。。。。。。。。。。。
</Data>
</Item>
<Item name="resname2">
<Description>
资源描述2
</Description>
<Data>
数据2。。。。。。。。。。。
</Data>
</Item>
</Resource>
——————————————————————————————

问题是,从文件中读取的xml的输出结果是乱码,而新建节点的输出结果正常

...全文
193 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangwm 2005-06-23
  • 打赏
  • 举报
回复
xml的第一句是该是
<?xml version="1.0" encoding="gb2312" ?>
MyGhosts 2005-06-23
  • 打赏
  • 举报
回复
把你的XML文件另存为(可复盖原文件),编码选 utf-8, 普通默认编码为 ANSI

楼主试试看,俺可不敢保证对;
blueonly 2005-06-23
  • 打赏
  • 举报
回复
我倒啊
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
忘加这句了
blueonly 2005-06-23
  • 打赏
  • 举报
回复
新的测试程序
<% option explicit %>
<!-- #include file="../class/CLSystem.asp" -->
<!-- #include file="../class/CLXML.asp" -->
<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' /></head><Body>
<%
dim o
set o=new clsXML
o.LoadFile("xml.xml")
Response.Write("<pre>" & o.Unicode(o.xml) & "</pre>")
'dim n
'set n=o.GetNode("/Resource/Item[@name='resname2']")
dim ln
set ln=o.Create("Item")
ln.appendchild(o.Create("Description"))
ln.appendchild(o.Create("Data"))
ln.childNodes(0).text="新建元素"
ln.childNodes(1).text="新建数据"
o.Root.appendchild(ln)
o.SaveFile("xml2.htm")
Response.Write("<pre>" & server.htmlencode(ln.XML) & "</pre>")
%>
</Body></html>
——————————————————————
xml.xml

<?xml version="1.0" encoding="UTF-8" ?>
<Resource xmlns:b="http://www.blue1018.net/resource">
<Item name="resname" >
<Description>
资源描述
</Description>
<Data>
数据。。。。。。。。。。。
</Data>
</Item>
<Item name="resname2">
<Description>
资源描述2
</Description>
<Data>
数据2。。。。。。。。。。。
</Data>
</Item>
</Resource>
______________________________
xml2.htm

<?xml version="1.0" encoding="UTF-8"?>
<Resource xmlns:b="http://www.blue1018.net/resource">
<Item name="resname">
<Description>
资源描述
</Description>
<Data>
数据。。。。。。。。。。。
</Data>
</Item>
<Item name="resname2">
<Description>
资源描述2
</Description>
<Data>
数据2。。。。。。。。。。。
</Data>
</Item>
<Item><Description>鏂板缓鍏冪礌</Description><Data>鏂板缓鏁版嵁</Data></Item></Resource>

注意最底下的是乱码
blueonly 2005-06-23
  • 打赏
  • 举报
回复
好像
microsoft.xmldom.documnet的 save 和 load 方法都会自动转换为gb2132
不知道有地方能设置吗
zwrtv 2005-06-23
  • 打赏
  • 举报
回复
路过学习下
blueonly 2005-06-23
  • 打赏
  • 举报
回复
我utf-8编码显示数据库中的数据都正常,问题出在microsoft.xmldom上?
blueonly 2005-06-23
  • 打赏
  • 举报
回复
回复人: MyGhosts(阿辉) ( ) 信誉:100 2005-06-23 12:43:00 得分: 0


把你的XML文件另存为(可复盖原文件),编码选 utf-8, 普通默认编码为 ANSI

楼主试试看,俺可不敢保证对;


_______________
本来就是utf-8
blueonly 2005-06-23
  • 打赏
  • 举报
回复
不能用utf-8吗,我不想用gb2132
白夜花寒 2005-06-23
  • 打赏
  • 举报
回复
encoding="gb2312"

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧