title: Traversing all nodes in an XML file with VBScript
body: <p>I have written a VBScript which is supposed to tranverse all nodes in an XML file, irrespective of the depth of the tree. This it does well <em>except</em> that the node names for the those nodes which are 2 or more levels deep are not displayed. I need the node names as well as the values so that I have name/value pairs for further processing by other programs. Can anyone please help me in getting the missing node names displayed.</p>
  
  <p>Below is my code:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;script type="text/vbscript"&gt;
  Set xmlDoc=CreateObject("Microsoft.XMLDOM")
  xmlDoc.async="false"
  xmlDoc.load("test.xml")
  Dim objDocElem, strNode, strSubNode, xmlnn, xmlnv, xmlnc, xmldd, xmlfd, xmlfv
  
  Set n_firstchild = xmldoc.documentElement.firstChild
  Set p_node = n_firstchild.parentNode
  Set pn_attribs = p_node.attributes
  For Each pnAttr in pn_attribs
     xmlfd = xmlfd &amp; pnAttr.name &amp; chr(9)
     xmlfv = xmlfv &amp; pnAttr.value &amp; chr(9)
  Next 
  
  Set objDocElem=xmlDoc.documentElement
  
  Set y = objDocElem.childNodes
  i=0
  Do While i &lt; y.length 
  If y(i).nodeType &lt;&gt; 3 Then
    If Isnull(y(i).childNodes(0).nodeValue) Then
       xmlnv = xmlnv &amp; "Category" &amp; chr(9)
    Else
       xmlnv = xmlnv &amp; y(i).childNodes(0).nodeValue &amp; chr(9)
    End If
    xmlnn = xmlnn &amp; y(i).nodeName &amp; chr(9)
    xmlnc = xmlnc + 1
    z=0
    Do While z &lt; y(i).childNodes.length
      If y(i).childNodes(z).nodeType &lt;&gt; 3 Then
         xmlnc = xmlnc + 1
         xmlnn = xmlnn &amp; y(i).childNodes(z).nodeName &amp; chr(9)
         xmlnv = xmlnv &amp; y(i).childNodes(z).text &amp; chr(9)
      End If
      z=z+1
    Loop
  End If
  i=i+1  
  Loop
  
  document.write("form details: " &amp; xmlfd &amp; "&lt;br /&gt;")
  document.write("form values: " &amp; xmlfv &amp; "&lt;br /&gt;&lt;br /&gt;")
  document.write("node names: " &amp; xmlnn &amp; "&lt;br /&gt;")
  document.write("node values: " &amp; xmlnv &amp; "&lt;br /&gt;")
  document.write("&lt;br /&gt;node count: " &amp; xmlnc &amp; "&lt;br /&gt;")
  
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and the XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" standalone="yes"?&gt;
  &lt;form penid="AJX-AAE-CRB-7P" submitted="2009-09-10 14:57:07" updated="2009-09-10 15:05:22" finalised="2009-09-10 15:59:48"&gt;
    &lt;Forename&gt;Russell&lt;/Forename&gt;
    &lt;Surname&gt;Kilby&lt;/Surname&gt;
    &lt;HouseNumber&gt;248&lt;/HouseNumber&gt;
    &lt;Letter&gt;GRG&lt;/Letter&gt;
    &lt;Products&gt;
      &lt;WinSoftware&gt;Product One&lt;/WinSoftware&gt;
      &lt;MacSoftware&gt;Product Two&lt;/MacSoftware&gt;        
      &lt;LnxSoftware&gt;Product Three&lt;/LnxSoftware&gt;
      &lt;Generic&gt;
          &lt;Product1&gt;Speedo&lt;/Product1&gt;
          &lt;Product2&gt;Switches&lt;/Product2&gt;
          &lt;Product3&gt;BIOS&lt;/Product3&gt;
          &lt;TestOne&gt;
              &lt;Panel1&gt;Front&lt;/Panel1&gt;
              &lt;Panel2&gt;Back&lt;/Panel2&gt;
              &lt;Panel3&gt;Middle&lt;/Panel3&gt;
          &lt;/TestOne&gt;
      &lt;/Generic&gt;
      &lt;Hardware&gt;Fender&lt;/Hardware&gt;
    &lt;/Products&gt;
    &lt;HouseName&gt;Just Tea House&lt;/HouseName&gt;
    &lt;PostCode&gt;B87 7DF&lt;/PostCode&gt;
    &lt;Insurer&gt;ABC Cars&lt;/Insurer&gt;
    &lt;PolicyNumber&gt;FDA 8D3JD7K&lt;/PolicyNumber&gt;
    &lt;Make&gt;Ford&lt;/Make&gt;
    &lt;VehicleReg&gt;EX51 CBA&lt;/VehicleReg&gt;
    &lt;DescriptionOfDamage&gt;Big smash on the from&lt;/DescriptionOfDamage&gt;
    &lt;Estimate&gt;1300&lt;/Estimate&gt;
    &lt;AlertManager&gt;Yes&lt;/AlertManager&gt;
  &lt;/form&gt;
  </code></pre>