Given this XML file
<?xml version="1.0"?><Locations>
<Location ID = "Austin">
<Strings>
<Root>"\\ausfs\"</Root>
<Jobs>"Austin Jobs"</Jobs>
<FlexLM_Servers>"@dallic01;@atllic01;@tamlic01"</FlexLM_Servers>
<RS_Accel>"ausrevitsvr01"</RS_Accel>
</Strings>
</Location>
<Location ID = "Denver">
<Strings>
<Root>"\\denfs\"</Root>
<Jobs>"Denver Jobs"</Jobs>
<FlexLM_Servers>"@dallic01;@atllic01;@tamlic01"</FlexLM_Servers>
<RS_Accel>"denrevitsvr01"</RS_Accel>
</Strings>
</Location>
</Locations>
I need a hash table populated with the key/value pairs from the Strings node, and named for the particular location.
I can get an arbitrary Location with
$LocationsNode = $xml.selectnodes("/Locations/Location") | Where {$_.ID -eq $Location}
Where $Location is the particular Location I am looking for. (And mind you, figuring out piping to Where was a major milestone in "think like PoSh, not like VBS" progress ;-)
And I can get the Strings node of that Location with
$StringsNode = $LocationsNode.selectnodes("./Strings")
But I seem unable to get to the contents once I have the appropriate Strings node. I have tried
foreach ($String in $StringsNode)
But that seems to produce the Strings node agin, which I don't understand.
Also, I should note that the name and number of tags in Strings is arbitrary, I just need to read them all and get them into a hash table.
Lastly, I am curious, what is the difference between defining the $XML variable and using Load vs the Get-Content approach? I have seen both, and not sure when one is better than the other.
Any help is greatly appreciated.
Gordon