gdanenb has asked for the wisdom of the Perl Monks concerning the following question:
For some reason when I append element to xml file, it's written in one line, i.e. not formatted
Original xml:
And the code is:<configuration> <property> <name>test1</name> </property> </configuration>
Which resulted with:my $parser =XML::LibXML->new(); my $doc =$parser->parse_file($file) or die $!; my $root =$doc->getDocumentElement; my $searchPath="/configuration"; my ($val)=$root->findnodes($searchPath); my $propTag=$doc->createElement("property"); $val->appendChild($propTag); my $nameTag=$doc->createElement("name"); $nameTag->appendTextNode($name); $propTag->appendChild($nameTag); $doc->setDocumentElement($root); $doc->toFile($file,1);
instead of:<configuration> <property> <name>test1</name> </property> <property><name>test2</name></property></configuration>
<configuration> <property> <name>test1</name> </property> <property> <name>test2</name> </property> </configuration>
Back to
Seekers of Perl Wisdom