Private/Wissen/X04_Technology_XML.ps1

# ? TITEL Verarbeiten von XML
# ? DESCRIPTION Mit XML umgehen
# ? TAGS
# ? VERSION 2019.11.08

# ? Beispiel für XPath unf Schematas
$xDoc = [xml](Invoke-WebRequest -Uri 'https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml' | Select-Object -ExpandProperty Content)
$namespaces = @{gesmes = "http://www.gesmes.org/xml/2002-08-01"
                ecb    = "http://www.ecb.int/vocabulary/2002-08-01/eurofxref"}
$x = $xDoc | Select-Xml -XPath "/gesmes:Envelope/ecb:Cube/ecb:Cube[@time='2019-11-05']" -Namespace $namespaces
$x.Node.Cube

# ? XML-Daten auswerten
[xml]$xDocument = Invoke-WebRequest -Uri "http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml" |
    Select-Object -ExpandProperty Content
[decimal]$rate = $xDocument.Envelope.Cube.Cube.Cube | 
    Where-Object -Property currency -EQ -Value "AUD" | Select-Object -ExpandProperty rate
$rate * 100

# ? In eine XML-Struktur schreiben
[xml]$config = @"
<?xml version="1.0" encoding="utf-8" ?>
<Einstellungen>
    <Server Name="ADC01" IP="127.0.0.1" />
    <Server Name="ADC02" IP="127.0.0.1" />
</Einstellungen>
"@

($config.Einstellungen.Server  | Where-Object -Property Name -Like -Value "*02").IP = "192.168.50.32"
$config.Save("C:\temp\einstellung.xml")
[xml]$result = Get-Content "C:\temp\einstellung.xml"
$result.Einstellungen.Server