Below is the simple perl code that will clean up the xml file. You can use XML::Tidy library.
use strict;
use XML::Tidy;
use Win32;
if ($ARGV[0] eq "") {
print "XML file is missing\n\t xmltidy.exe \"File.xml\"\n"
}else
{
if ($ARGV[0]!~ /.xml$/){print "XML file is missing\n\t xmltidy.exe \"File.xml\"\n";exit;}
my $xml=$ARGV[0];
if (!(-f $ARGV[0])) {$xml=Win32::GetCwd().'\\'.$ARGV[0]} ;
# create new XML::Tidy object from MainFile.xml
my $tidy_obj = XML::Tidy->new('filename' => $xml);
# Tidy up the indenting
$tidy_obj->tidy();
# Write out changes back to MainFile.xml
$tidy_obj->write();
}