• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

遍历XML文档返回二维数组(ASP)(更新版)

发布: 2007-6-30 18:56 | 作者: admin | 来源: | 查看: 52次 | 进入软件测试论坛讨论

领测软件测试网  

<% on error resume next
   ‘’<![CDATA[]]>问题没处理
   ‘’xmlfile = "???.xml"
   Set xml = Server.CreateObject("MSXML.DOMDocument")
   xml.async = false
   xml.load(xmlfile)


Public Function PrettyPrint(node,tabLevel)
on error resume next
 If node.nodeName <> vbNullStrin And node.nodeName <> "#text" Then
  PrettyPrint = PrettyPrint & tabLevel & "[sp2]0[sp2]" + node.nodeName + "[sp1]"

   For Each i In node.Attributes
    pstr = pstr + i.Name + "=" + i.Value + " "
   Next
  PrettyPrint = PrettyPrint & tabLevel & "[sp2]2[sp2]" + pstr + "[sp1]"
 End If
 If node.hasChildNodes Then
  For Each childNode In node.childNodes
   tabLevel=tabLevel+1
   PrettyPrint = PrettyPrint + PrettyPrint(childNode, tabLevel)
  Next
 Else
  PrettyPrint = PrettyPrint & tabLevel-1 & "[sp2]1[sp2]" + node.Text + "[sp1]"
 End If
End Function

Public Function ShowXml(s)
on error resume next
 ta = split(s,"[sp1]")
 k = ubound(ta)-1
 ‘’response.write "sta(" &k &",2)<p>"
 redim sta(k,2)
 for i = 0 to k
  ta2 = split(ta(i),"[sp2]")
  cs1 = ta2(0)
  cs2 = ta2(1)
  cs3 = ta2(2)
  ‘’Response.write "sta(" & cs1 & "," & cs2 & ") = " & cs3 & "<br>"
  sta(cs1,cs2) = cs3
 Next
 ShowXml = sta
End Function

test = ShowXml(PrettyPrint(xml.documentElement,0))

   response.write "<table width=100% border=1 bgcolor=#dddddd>" + chr(13)
   response.write "<tr bgcolor=#767A7D>"
   response.write "<td>nodeName</td><td>nodeValue</td><td>Attributes</td>"
   response.write "</tr>" + chr(13)
   for b = 0 to ubound(test)
 If test(b,0)<>"" then
 response.write "<tr "
 If b=0 then response.write "bgcolor=#939495" end if
 If IsEmpty(test(b,1)) and b<>0 then response.write "bgcolor=#BABBBC" end if
 response.write ">"
 response.write "<td>" & test(b,0) & "&nbsp;</td>"
 response.write "<td>" & test(b,1) & "&nbsp;</td>"
 response.write "<td>" & test(b,2) & "&nbsp;</td>"
 response.write "</tr>" + chr(13)
 End if
   next
   response.write "</table>"

%>

PrettyPrint函数返回字符串

ShowXml函数处理PrettyPrint的返回值并返回一个二维数组

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网