title: vba - finding the xpath of a node
body: <p>c.Value is a text from a cell (typical values are: name, type, weight, currency but could be anything) in the first row of the sheet.</p>
  
  <p>filenames is a loop from Dir() basically looping thru XMLs in a folder.</p>
  
  <p>These xmls may have  the lowest level node 'weight' (for example) but under multiple different parent nodes. Ie these 3 different xpaths: //Client/personal/weight and //Client/details/weight and //Client/details/info/weight.</p>
  
  <p>I've got this code:</p>
  
  <pre><code>   Dim aDoc As DOMDocument
      Dim aNode As IXMLDOMNode
      Set aDoc = LoadXmlDoc(filenames(f))
      Set aNodes = aDoc.getElementsByTagName(c.Value)
  For f = 1 To UBound(filenames)
      If aNodes.Length &gt; 0 Then 'if at least one node is present
         For Each aNode In aNodes 'loop thru each occurence of a node
            c.Offset(f, 0).Value = aNode.Text &amp; "parent is " &amp; aNode.parentNode.parentNode
         Next
      End If
  Nxt f
  </code></pre>
  
  <p>What I'm trying to do is get a distinct list of the xpaths for the child node I specify in c.value.</p>
  
  <p>For example,</p>
  
  <pre><code>if c.value is weight
  </code></pre>
  
  <p>I'm trying to get this list back:</p>
  
  <pre><code>//Client/personal/weight
  //Client/details/weight
  //Client/details/info/weight.
  </code></pre>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/aa163921(office.10).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa163921(office.10).aspx</a> is a good reference but I can't seem to find how to get the xpath from a child node. I just managed to get the immediate parent node.</p>