title: XPath Classic ASP
body: <p>Obviously I'd much rather batter the person who decided that spitting out xml like the following was a good idea, but alas, I can't. ;-)</p>
  
  <p>I have the following xml:</p>
  
  <pre><code>&lt;search&gt;
      &lt;key_0&gt;
          &lt;ContentTitle&gt;blah&lt;/ContentTitle&gt;
      &lt;/key_0&gt;
      &lt;key_1&gt;
          &lt;ContentTitle&gt;blah blah&lt;/ContentTitle&gt;
      &lt;/key_1&gt;
  &lt;/search&gt;
  </code></pre>
  
  <p>What would be the correct xpath to get the data out.
  If, as it should, the node names were 'key' each time, the following asp, with the xpath of //search/key would do the job perfectly. However, I can't work out the correct xpath / way of doing this, or how to modify the code otherwise.</p>
  
  <p>Anyone any ideas? Thanks</p>
  
  <pre><code>Dim mydoc : Set mydoc=Server.CreateObject("Microsoft.XMLDOM") 
  mydoc.async=false
  mydoc.loadXML(xmlFile)
  
  If mydoc.parseError.errorcode&lt;&gt;0 then
      Response.write mydoc.parseError.errorcode &amp; " is the error code!&lt;br /&gt;"
  Else
      Set xmlPNode = mydoc.selectNodes("//search/key")
  
      If(xmlPNode.Length=0) Then
          response.write "No results found!"
      Else
          Dim iTotalResults : iTotalResults = (xmlPNode.Length - 1)
          Dim i
          For i = 0 to  iTotalResults
              strContentTitle=GetXMLItem("ContentTitle", i)
          Next
  End If
  Set xmlPNode = Nothing
  End if
  
  
  Function GetXMLItem(strpItem, ipValue)
      Dim nlOutput : Set nlOutput = xmlPNode(ipValue).selectNodes(strpItem) 
      If(nlOutput.Length&lt;&gt;0) Then
          GetXMLItem=nlOutput(0).Text
      Else
          GetXMLItem=""
      End If
  End Function
  </code></pre>