Last active
September 1, 2017 10:05
-
-
Save RichieBzzzt/f27e7837f009676a89f896dbb7bc70df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[xml] $x = '<Lunch> | |
<Sandwiches> | |
<Sandwich Include="Mixte"> | |
<Filling>Ham and Emmantal Cheese</Filling> | |
</Sandwich> | |
<Sandwich Include="RoteDeBoeuf"> | |
<Filling>Beef and Mustard Mayonnaise</Filling> | |
</Sandwich> | |
</Sandwiches> | |
</Lunch>' | |
$Mixte = "Fromage au jambon et Emmantal" | |
$RoteDeBoeuf = "Mayonnaise au boeuf et à la moutarde" | |
$keys = $($x.Lunch.Sandwiches.Sandwich) | |
foreach ($var in $keys) { | |
$update = $var.Include | |
if (Test-Path variable:$update) { | |
[string]$value = Get-Variable $update -ValueOnly | |
Write-Verbose ('Setting variable: {0} = {1}' -f $update, $value) -Verbose | |
$element = $x.SelectNodes("/Lunch/Sandwiches/Sandwich") | Where-Object {$_.Include -eq $update} | |
$element.Filling = $value | |
} | |
else { | |
$missingVariables += $var | |
} | |
} | |
if ($missingVariables.Count -gt 0) { | |
throw ('The following variables are not defined in the current scope (but are defined in the xml): {0}' -f ($missingVariables -join " `n")) | |
} | |
$x.Lunch.Sandwiches.Sandwich |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment