CSDN博客

img superdullwolf

解析Dom节点和属性

发表于2004/10/3 15:43:00  992人阅读

<style>
table
{
 border-collapse: collapse;
 border-width: 4;
 border-style: double;
 border-color:#15336F;
 font-size:12px;
}
body
{
 font-size:12px;
}
</style>
 
 <table border="1">
 <tr>
  <td> 节点名称 </td><td> 属性名称 </td>
 </tr>
 <script language="vbScript" >
 
  public dic,doc
  set dic = CreateObject("Scripting.Dictionary") 
  set doc = CreateObject("Microsoft.XMLDOM")  
  doc.async=False
 
  if not doc.load("cmp.xml") then
   alert "文件加载失败,请检查文件是否存在!" 
  else
  Set rootNode = doc.DocumentElement
  getnode rootNode


  for each kkk in dic.Keys
   document.write  "<tr><td>" & kkk & "</td><td>"
   if len(trim(dic.Item(kkk))) > 0 then
    document.write  dic.Item(kkk) & "</tr>"
   else
    document.write  "&nbsp;" & "</tr>"
   end if
  next
  end if
 
 sub getnode(myNode)  
  for each childNode in myNode.childNodes
   if childNode.nodeName<>"#text" then
    if not(dic.Exists(childNode.nodeName)) then
     if childNode.Attributes.length>0 then
      dic.Add childNode.nodeName,  makeString(childNode.Attributes )
     else
      dic.Add childNode.nodeName,""
     end if
    else
     dic.Item(childNode.nodeName) = exclude(dic.Item(childNode.nodeName),childNode.Attributes )
    end if
   end if
   if childNode.childNodes.length > 0 then getnode childNode
  next 
 end sub 

 function exclude(myString,collection)
  dim sss,ccc,kkk,d
  set d = CreateObject("Scripting.Dictionary")

  for each sss in split(myString,",")
   if not d.Exists(sss) then d.Add sss,sss  
  next
  
  for each ccc in collection
   if not d.Exists(ccc.name) then d.Add ccc.name,ccc.name  
  next

  for each kkk in d.Keys
   exclude = exclude  & kkk  & " "
  next

  exclude = replace(trim(exclude)," ",",")
 end function
 
 function makeString(collection)
  dim ccc
  makeString = " "
  
  for each ccc in  collection
   makeString = makeString & ccc.name & " "
  next
  makeString = replace(trim(makeString)," ",",")
 end function
 
 </script>
 </table>

阅读全文
0 0

相关文章推荐

img
取 消
img