title: How to find whether attributes with specific values exist in the XML child elements?
body: <p>I am trying to find out whether an XML Attribute with a specific value exists or not in each child element of the xml document root. My code is as follows:</p>
  
  <pre><code>Option Explicit
  Dim sheet As Worksheet
  Dim rowCount1, i As Integer
  Dim xNode As MSXML2.IXMLDOMNode
  Dim xDoc As MSXML2.DOMDocument
  Dim Nodes As MSXML2.IXMLDOMNodeList
  
  Public Sub LoadDocument()
  rowCount1 = 0
  Set xDoc = New MSXML2.DOMDocument
  xDoc.validateOnParse = False
   If xDoc.load("D:\Feedroutes.xml") Then ' The document loaded successfully.
    Set Nodes = xDoc.SelectNodes("//Property[@name='Value']")
    AttributesToColumns
    Else
   ' The document failed to load.
   End If
  End Sub
  
  Public Sub AttributesToColumns()
   Set sheet = ActiveSheet
  
   For Each xNode In Nodes
    If Not Nodes Is Nothing Then
     rowCount1 = rowCount1 + 1
     sheet.Cells(rowCount1, 3).Value = xNode.Text
    'I want to increment the rowCount even if the attribute with the
    'specific value doesn't exist
    ElseIf Nodes Is Nothing Then
    rowCount1 = rowCount1 + 1
  
    End If
   Next xNode
  End Sub
  </code></pre>
  
  <p>At present it only writes the values of the attributes in successive rows, whereas the desired output is, write only in rows where the attribute with the specific value is present. My XML looks like this:</p>
  
  <pre><code>&lt;Tag name="PosLim" path="Feeders/R1" type="OPC"&gt;
    &lt;Property name="Value"&gt;0.0&lt;/Property&gt;
    &lt;Property name="DataType"&gt;4&lt;/Property&gt;
    &lt;Property name="OPCServer"&gt;Ignition OPC-UA Server&lt;/Property&gt;
    &lt;Property name="OPCItemPath"&gt;[Siemens]DB141,I74&lt;/Property&gt;
    &lt;Property name="ScaleMode"&gt;1&lt;/Property&gt;
    &lt;Property name="RawHigh"&gt;1000.0&lt;/Property&gt;
    &lt;Property name="FormatString"&gt;#,##0.00&lt;/Property&gt;
    &lt;Property name="EngUnit"&gt;Kg&lt;/Property&gt;
  &lt;/Tag&gt;
  &lt;Tag name="JogSettle" path="Feeders/R1" type="OPC"&gt;
    &lt;Property name="DataType"&gt;1&lt;/Property&gt;
    &lt;Property name="OPCServer"&gt;Ignition OPC-UA Server&lt;/Property&gt;
    &lt;Property name="OPCItemPath"&gt;[Siemens]DB141,I96&lt;/Property&gt;
    &lt;Property name="RawHigh"&gt;1000.0&lt;/Property&gt;
    &lt;Property name="FormatString"&gt;#,##0&lt;/Property&gt;
    &lt;Property name="EngUnit"&gt;S&lt;/Property&gt;
  &lt;/Tag&gt;
  &lt;Tag name="Positive Tol" path="Feeders/R1" type="OPC"&gt;
    &lt;Property name="Value"&gt;0.0&lt;/Property&gt;
    &lt;Property name="DataType"&gt;4&lt;/Property&gt;
    &lt;Property name="OPCServer"&gt;Ignition OPC-UA Server&lt;/Property&gt;
    &lt;Property name="OPCItemPath"&gt;[Siemens]DB141,I78&lt;/Property&gt;
    &lt;Property name="ScaleMode"&gt;1&lt;/Property&gt;
    &lt;Property name="RawHigh"&gt;1000.0&lt;/Property&gt;
    &lt;Property name="FormatString"&gt;#,##0.00&lt;/Property&gt;
    &lt;Property name="EngUnit"&gt;Kg&lt;/Property&gt;
  &lt;/Tag&gt;
  </code></pre>
  
  <p>My purpose is to write the values of attribute "name" where name = "Value" and all the other attributes as well in corresponding rows, not successive rows. So from the xml file above, my excel output should be:</p>
  
  <pre><code>   Row No.   Value        ScaleMode 
     Row1        0             1 
     Row2 
     Row3        0             1 etc
  </code></pre>