title: How can I select specific XML nodes in Powershell from multiple node values?
body: <p>I have the following XML syntax and I'm trying to obtain the value in Node ID "2", Row Key "Vol2-3" for now:</p>
  
  <pre><code>&lt;nodes&gt;
     &lt;node id="1"&gt;
       &lt;store&gt;
          &lt;row key="Vol1-1" value="1a"/&gt;
          &lt;row key="Vol1-2" value="1b"/&gt;
          &lt;row key="Vol1-3" value="1c"/&gt;
          &lt;row key="Vol1-4" value="1d"/&gt;
  &lt;/store&gt;
  &lt;/node&gt;
     &lt;node id="2"&gt;
       &lt;store&gt;
          &lt;row key="Vol2-1" value="2a"/&gt;
          &lt;row key="Vol2-2" value="2b"/&gt;
          &lt;row key="Vol2-3" value="2c"/&gt;
          &lt;row key="Vol2-4" value="2d"/&gt;
  &lt;/store&gt;
  &lt;/node&gt;
     &lt;node id="3"&gt;
       &lt;store&gt;
          &lt;row key="Vol3-1" value="3a"/&gt;
          &lt;row key="Vol3-2" value="3b"/&gt;
          &lt;row key="Vol3-3" value="3c"/&gt;
          &lt;row key="Vol3-4" value="3d"/&gt;
  &lt;/store&gt;
  &lt;/node&gt;
  &lt;/nodes&gt;
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>$nodevar=2 
  [xml]$XMLDoc=(Get-Content "\..\..somefile.txt")
  $value_extract=$XMLDoc.nodes.SelectNodes("node[@id='$nodevar']").store.SelectNodes("row[@key='']")
  </code></pre>
  
  <p>The issue I have is that I'm trying to set my $value_extract variable to pivot from the correct node ID to get to the corresponding row key containing my value. I wrote it in such a way that I'll eventually be using the SelectNodes in a for loop to obtain the values I need for further processing. Is there a good way to write this since I'm pivoting off of the correct node ID as well as the correct row key?</p>