I am trying to use PowerShell to format a messy XML file to a file with indentation where every tag starts on a new line.
The input file looks like:
<?xml version="1.0" encoding="WINDOWS-1252"?>
<RESULT>
<HEADER><ACCOUNT>035574623593</ACCOUNT><DATE_FROM>20150101</DATE_FROM><DATE_TO>20150526</DATE_TO><DATE_EQUAL></DATE_EQUAL><HD_DATIN>2015-11-27 15:16:52</HD_DATIN><HD_START>2015-11-27 15:16:52</HD_START><HD_ENGINE>WCV00228</HD_ENGINE><HD_QUERYID>984</HD_QUERYID></HEADER>
<FOOTER><FT_STATUS>NF</FT_STATUS><FT_RECORDS>2</FT_RECORDS><FT_SIZE>282</FT_SIZE><FT_ORDER>1</FT_ORDER><FT_STOP>2015-11-27 15:16:53</FT_STOP></FOOTER>
</RESULT>
This is a piece of my code where the formatting takes place:
function Format-XML {
Param ([string]$xmlfile)
$Doc=New-Object System.Xml.XmlDataDocument
$doc.Load($xmlfile)
$sw = New-Object System.IO.StringWriter
$settings = New-Object System.Xml.XmlWriterSettings
$settings.NewLineOnAttributes = $false
$settings.Indent = 1
$settings.NewLineOnAttributes = $true
$writer = [System.xml.XmlWriter]::Create($sw, $settings)
$doc.WriteContentTo($writer)
$sw.ToString()
}
Format-XML ("${app}se-xf-out\UH99DEFI.BEMVS000.U$datum.T$counter") > "${app}se-xf-out\UH99DEFI.BEMVS001.U$datum.T$counter"
Can someone help me? The output file is empty (but still 1kb).