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>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem to add xml element in a formatted structure
by tobyink (Canon) on Feb 09, 2012 at 11:06 UTC | |
by gdanenb (Acolyte) on Feb 09, 2012 at 12:44 UTC | |
by MidLifeXis (Monsignor) on Feb 09, 2012 at 13:22 UTC | |
by tobyink (Canon) on Feb 09, 2012 at 15:12 UTC | |
|
Re: Problem to add xml element in a formatted structure
by choroba (Cardinal) on Feb 09, 2012 at 12:49 UTC |