Skip to content

Instantly share code, notes, and snippets.

@marcgeld
Last active April 5, 2017 09:28
Show Gist options
  • Save marcgeld/8078f0100db1226e89662cafb99a9ddb to your computer and use it in GitHub Desktop.
Save marcgeld/8078f0100db1226e89662cafb99a9ddb to your computer and use it in GitHub Desktop.
Powershell: Create and print xml document
# Create and print xml document
[System.Xml.XmlDocument] $xml =
@'
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<a><b><c><d text="Hello" /> </c></b></a>
<a><b><c><d text=" " /> </c></b></a>
<a><b><c><d text="World" /> </c></b></a>
</root>
'@
$StringWriter = New-Object System.IO.StringWriter;
$XmlWriter = New-Object System.Xml.XmlTextWriter $StringWriter;
$XmlWriter.Formatting = "indented";
$xml.WriteTo( $XmlWriter );
$XmlWriter.Flush();
$StringWriter.Flush();
[string] $str = $StringWriter.ToString()
Write-Host ( $str | Format-Table | Out-String )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment