Skip to content

Instantly share code, notes, and snippets.

@rewida17
Last active March 26, 2022 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rewida17/28e705620d71bfd33404a68741dba941 to your computer and use it in GitHub Desktop.
Save rewida17/28e705620d71bfd33404a68741dba941 to your computer and use it in GitHub Desktop.
# Beautify xml
# Ref: https://devblogs.microsoft.com/powershell/format-xml/
function Format-XML ([xml]$xml)
{
$StringWriter = New-Object System.IO.StringWriter
$XmlWriter = New-Object System.XMl.XmlTextWriter $StringWriter
$xmlWriter.Formatting = “indented”
$xmlWriter.Indentation = 4
$xml.WriteContentTo($XmlWriter)
$XmlWriter.Flush()
$StringWriter.Flush()
$StringWriter.ToString()
}
# Get minified xml data
$header= @{"Accept" = "application/xml"}
$RawData = ( Invoke-WebRequest -UseBasicParsing -Uri "http://api.nbp.pl/api/exchangerates/tables/a" -Headers $header -Method Get ).content
Format-XML $RawData | Out-File -Encoding utf8 -FilePath C:\Dane\TabA.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment