'Using XMLReader IgnoreWhiteSpace to reduce file size
I am taking an XML file and modifying it with the aim to reduce the file size.
My final file is currently 600MB, which for me is still too large.
I have found that if you use an XMLReader you can apply a setting to "IgnoreWhiteSpace", which in turn brings the file size down. I have seen something similar to this working elsewhere.
I have tried the following, however this is having the opposite effect and is increasing the size to 800MB
$readerSettings.IgnoreWhitespace = $true;
$readerSettings.IgnoreComments = $true;
$str = Get-Content C:/Temp/Test.xml -Raw
$stringReader = new-object system.io.stringreader $str
[System.Xml.XmlReaderSettings] $readerSettings = New-Object -TypeName System.Xml.XmlReaderSettings
$readerSettings.IgnoreWhitespace = $true;
$readerSettings.IgnoreComments = $true;
$reader = [System.Xml.XmlReader]::Create("C:/Temp/Test.xml", $readerSettings)
$to = "C:/Temp/Test-Final2.xml"
$toXml = [System.XML.XmlWriter]::Create($to)
$toXml.WriteNode($reader,$true)
$toXml.Flush()
$toXml.Close()
$reader.Close()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
