ASP解析XML问题
时间:2009-11-27
来源:互联网
客户给我们的数据是以XML形式返回的
[ 本帖最后由 ddd50 于 2009-11-27 12:41 编辑 ]
复制内容到剪贴板
<eps>
<count size="518" />
<data>
<record eps="AAABBB" fl="8800" />
<record eps="AABB" fl="8800" />
<record eps="ABCABC" fl="8800" />
<record eps="AABBCC" fl="8800" />
<record eps="ABABAB" fl="8800" />
<record eps="ABCABC" fl="8800" />
<record eps="AAABBB" fl="8800" />
<record eps="ABCAAB" fl="50" />
</data>
</eps>
对ASP DOM不太了解,有知道的能给指导一下吗,或者给些代码段参考,谢谢代码:
<?xml version="1.0" encoding="utf-8" ?><eps>
<count size="518" />
<data>
<record eps="AAABBB" fl="8800" />
<record eps="AABB" fl="8800" />
<record eps="ABCABC" fl="8800" />
<record eps="AABBCC" fl="8800" />
<record eps="ABABAB" fl="8800" />
<record eps="ABCABC" fl="8800" />
<record eps="AAABBB" fl="8800" />
<record eps="ABCAAB" fl="50" />
</data>
</eps>
[ 本帖最后由 ddd50 于 2009-11-27 12:41 编辑 ]
作者: ddd50 发布时间: 2009-11-27
不太明白你问什么?是问返回的XML怎样用asp读取处理?还是问什么?
作者: ggloverv 发布时间: 2009-11-27
对的,就是这个,用ASP解析返回的XML数据
作者: ddd50 发布时间: 2009-11-27
看例子.
data.xml(保存为UTF-8格式)
data.xml(保存为UTF-8格式)
<?xml version="1.0" encoding="utf-8" ?> <eps> <count size="518" /> <data> <record eps="AAABBB" fl="8800" /> <record eps="AABB" fl="8800" /> <record eps="ABCABC" fl="8800" /> <record eps="AABBCC" fl="8800" /> <record eps="ABABAB" fl="8800" /> <record eps="ABCABC" fl="8800" /> <record eps="AAABBB" fl="8800" /> <record eps="ABCAAB" fl="50" /> </data> <title><![CDATA[测试]]></title> </eps>
提示:您可以先修改部分代码再运行
read.asp(文件名任意,扩展名为asp,文件编码任意)提示:您可以先修改部分代码再运行
<% Dim xmlReader, record Response.Write("从xml文件中读取<br/>") '从文件中读取 Set xmlReader = Server.CreateObject("msxml.domdocument") xmlReader.load(Server.Mappath("data.xml")) 'count size Response.Write(xmlReader.documentElement.selectNodes("/eps/count")(0).getAttribute("size") & "<br>") Set record = xmlReader.documentElement.selectNodes("/eps/data/record") Response.Write("Record个数:" & record.length & "<br/>") for i=0 to record.length-1 Response.Write((i+1) & "=====> eps:" & record(i).getAttribute("eps") & "____________fl:" & record(i).getAttribute("fl") & "<br/>") Next 'title Response.Write(xmlReader.documentElement.selectNodes("/eps/title")(0).firstChild.nodeValue & "<br>") Set xmlReader = Nothing Response.Write("<hr>从xml字符串中读取<br/>") '从xml字符串中读取 Dim xml xml = "<?xml version=""1.0"" encoding=""utf-8"" ?>" &_ "<eps>" &_ " <count size=""518"" />" &_ " <data>" &_ " <record eps=""AAABBB"" fl=""8800"" />" &_ " <record eps=""AABB"" fl=""8800"" />" &_ " <record eps=""Hello worldABC"" fl=""8800"" />" &_ " <record eps=""AABBCC"" fl=""8800"" />" &_ " <record eps=""ABABAB"" fl=""8800"" />" &_ " <record eps=""ABCABC"" fl=""8800"" />" &_ " <record eps=""AAABBB"" fl=""8800"" />" &_ " <record eps=""ABCAAB"" fl=""50"" />" &_ " </data>" &_ " <title><![CDATA[测试]]></title>" &_ "</eps>" Set xmlReader = Server.CreateObject("msxml.domdocument") xmlReader.loadXML(xml) 'count size Response.Write(xmlReader.documentElement.selectNodes("/eps/count")(0).getAttribute("size") & "<br>") Set record = xmlReader.documentElement.selectNodes("/eps/data/record") Response.Write("Record个数:" & record.length & "<br/>") for i=0 to record.length-1 Response.Write((i+1) & "=====> eps:" & record(i).getAttribute("eps") & "____________fl:" & record(i).getAttribute("fl") & "<br/>") Next 'title Response.Write(xmlReader.documentElement.selectNodes("/eps/title")(0).firstChild.nodeValue & "<br>") Set xmlReader = Nothing %>
提示:您可以先修改部分代码再运行
asp读取xml在线演示地址 提示:您可以先修改部分代码再运行
作者: faeng220 发布时间: 2009-11-27
按照一摸一样的代码运行,有提示出错,出错信息如下:
错误类型:
Microsoft VBScript 运行时错误 (0x800A01A8)
缺少对象: '[object]'
/xmltest.asp, 第 65 行
第65行代码是:
Response.Write(xmlReader.documentElement.selectNodes("/eps/count")(0).getAttribute("size") & "<br>")
错误类型:
Microsoft VBScript 运行时错误 (0x800A01A8)
缺少对象: '[object]'
/xmltest.asp, 第 65 行
第65行代码是:
Response.Write(xmlReader.documentElement.selectNodes("/eps/count")(0).getAttribute("size") & "<br>")
作者: kennyyu79 发布时间: 2011-10-07
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28