I want to update attributes in xml using perl.The problem here is when I am updaing the attributes of xml it is happening but the xml format is being changed.Breaking my head but no use !
Can anyone pls suggest me some perl code to update attributes in xml with out affecting the xml format
I used the perl code as shown below
#!/usr/bin/perl
use strict;
use warnings;
use XML::Simple;
my $xml_file = '3.xml';
my $xml = XMLin(
$xml_file,
KeepRoot => 1,
ForceArray => 1
);
$xml->{outer1}->[0]->{inner1}->[1]->{name}->[0]->{first} = 'Shane Bond';
XMLout(
$xml,
KeepRoot => 1,
NoAttr => 1,
OutputFile => $xml_file,
);
Input xml:
<outer1>
<inner1>
<name>Stonecold</name>
<org>wwf</org>
<profession>
<Bowler>hai</Bowler>
</profession>
</inner1>
<inner1>
<name first = "Shanebond" />
<org>newzealand</org>
<profession>Shane Bond</profession>
</inner1>
<inner1>
<name>brain schemidit</name>
<org>Google</org>
<profession>Chairman</profession>
</inner1>
</outer1>
Expected Output xml:
<outer1>
<inner1>
<name>Stonecold</name>
<org>wwf</org>
<profession>
<Bowler>hai</Bowler>
</profession>
</inner1>
<inner1>
<name first = "Shane Bond" />
<org>newzealand</org>
<profession>Shane Bond</profession>
</inner1>
<inner1>
<name>brain schemidit</name>
<org>Google</org>
<profession>Chairman</profession>
</inner1>
</outer1>
Actual Output xml:
<outer1>
<inner1>
<name>Stonecold</name>
<org>wwf</org>
<profession>
<Bowler>hai</Bowler>
</profession>
</inner1>
<inner1>
<name>
<first>Shane Bond</first>
</name>
<org>newzealand</org>
<profession>Shane Bond</profession>
</inner1>
<inner1>
<name>brain schemidit</name>
<org>Google</org>
<profession>Chairman</profession>
</inner1>
</outer1>