I have the following XML syntax and I'm trying to obtain the value in Node ID "2", Row Key "Vol2-3" for now:
<nodes>
<node id="1">
<store>
<row key="Vol1-1" value="1a"/>
<row key="Vol1-2" value="1b"/>
<row key="Vol1-3" value="1c"/>
<row key="Vol1-4" value="1d"/>
</store>
</node>
<node id="2">
<store>
<row key="Vol2-1" value="2a"/>
<row key="Vol2-2" value="2b"/>
<row key="Vol2-3" value="2c"/>
<row key="Vol2-4" value="2d"/>
</store>
</node>
<node id="3">
<store>
<row key="Vol3-1" value="3a"/>
<row key="Vol3-2" value="3b"/>
<row key="Vol3-3" value="3c"/>
<row key="Vol3-4" value="3d"/>
</store>
</node>
</nodes>
Code:
$nodevar=2
[xml]$XMLDoc=(Get-Content "\..\..somefile.txt")
$value_extract=$XMLDoc.nodes.SelectNodes("node[@id='$nodevar']").store.SelectNodes("row[@key='']")
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?