I'm writing a script at the moment, the main aim of which is to locally interrogate a series of XML files on a target computer and re-create them if they are found to be corrupted or missing for whatever reason.
The problem that I'm having is that there is a particular XML file used by the FileZilla Server application that has no XML declaration and no indentation on it's nodes. As these values are static, I simply created a System.Xml.XmlDocument
variable and copied the data within a working XML file and pasted it into the argument parentheses of the .LoadXml()
function without indentation, like so;
$xmlFileZillaServer= New-Object System.Xml.XmlDocument
$xmlFileZillaServer.LoadXml('
<FileZillaServer>
<Settings>
<Item name="Serverport" type="numeric">21</Item>
<Item name="Number of Threads" type="numeric">2</Item>
<Item name="Maximum user count" type="numeric">0</Item>
<Item name="Timeout" type="numeric">120</Item>
<Item name="No Transfer Timeout" type="numeric">120</Item>
etcetera...
However, the output of the XML is indented, as follows;
<FileZillaServer>
<Settings>
<Item name="Serverport" type="numeric">21</Item>
<Item name="Number of Threads" type="numeric">2</Item>
<Item name="Maximum user count" type="numeric">0</Item>
<Item name="Timeout" type="numeric">120</Item>
<Item name="No Transfer Timeout" type="numeric">120</Item>
etcetera...
How can I stop LoadXml
from putting this indentation in automatically? Or am I going to have to use an XmlTextWriter
object to write the XML manually and specify the indentation configuration during the write process?