I wrote the following Perl script (below) in order to create simple XML file. The generated output is valid, but I have specific formatting requirements for the generated XML source code.
How can I change my script to add the whitespace I desire?
#!/usr/bin/perl
use warnings;
use XML::LibXML;
my $doc = XML::LibXML::Document->new;
my $root = $doc->createElement('LEVEL1');
$doc->setDocumentElement($root);
my $system = $doc->createElement('LEVEL2');
$root->appendChild($system);
my $install = $doc->createElement('LEVEL3');
$system->appendChild($install);
print $doc->toString;
Output of the script:
<?xml version="1.0"?>
<LEVEL1><LEVEL2><LEVEL3/></LEVEL2></LEVEL1>
Desired output:
<?xml version="1.0"?>
<LEVEL1>
<LEVEL2>
<LEVEL3/>
</LEVEL2>
</LEVEL1>