Formatting xml with powershell

Published on den 8 May 2013

Ever had to work with an xml file where the xml was minified to one line? Fear not, only two powershell commands are needed to fix it.

Sometimes XML files are minified by removing whitespace which might be good for space but a real pain in the ass if you need to manually read it. Furthermore most texteditors are made to work efficiently with documents that has many rows but long rows are another story..

Luckily it takes only a few seconds to fix it if you know your powershell.

 [xml]$xml = Get-Content resultlist.xml  
 $xml.Save("d:/test.xml")

That's actually all you need. Happy formatting!

Then feel free to it or if you have any comments or questions mention @MikaelEliasson on Twitter.

CTO and co-founder at Bokio with a background as an elite athlete. Still doing a lot of sports but more for fun.

#development, #web, #orienteering, #running, #cycling, #boardgames, #personaldevelopment