Last active
          April 5, 2017 09:28 
        
      - 
      
 - 
        
Save marcgeld/8078f0100db1226e89662cafb99a9ddb to your computer and use it in GitHub Desktop.  
    Powershell: Create and print xml document
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | # 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