遍历XML文档的所有节点及属性(ASP)

发表于:2007-06-30来源:作者:点击数: 标签:
% on error resume next ‘’![CDATA[]]问题没处理 xmlfile = "???.xml" Set xml = Server.CreateObject("MSXML.DOMDocument") xml.async = false xml.load(xmlfile) private function showxml(node) dim tempstr for each i in node If i.nodeType = 1 then

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

   private function showxml(node)
   dim tempstr
   for each i in node

 If i.nodeType = 1 then
 tempstr = "<b>" & i.nodeName & "</b>"
 tempstr = replace(tempstr,"#text","")
 Response.write tempstr
 end if

 If i.nodeType = 3 then
 tempstr = "<i>" & i.nodeValue & "</i><br>"
 response.write tempstr
 end if

 If i.nodeName<>"#text" then
 for each b in i.attributes
  response.write "[" & b.name & ":" & b.value & "] "
 Next
 Response.write "<br>"
 end if
 If i.hasChildNodes then
  showxml(i.childNodes)
 end if
   Next
   End function

   showxml(xml.documentElement.childNodes)
%>


原文转自:http://www.ltesting.net