The simple solution to your problem is to provide the same value for the
keyattr option to XMLout as you provided to XMLin:
print XMLout($xml, noattr => 1, keyattr => { location => 'name', lab
=> 'name', host => 'IPaddress'});
The cause is that you specifically asked XMLin to fold the list of hosts
into an array keyed on IPaddress; but when you called XMLout, you relied
on the default value of keyattr to unfold the hash of hashes. When
reading, the IPaddress tag name was discarded, but when writing you did
not provide sufficient information to allow XML::Simple to reconstruct
the discarded information.
See more info here:
http://www.perlmonks.org/index.pl?node_id=218480
Secondly, when you need to supply the same options to XMLout as XMLin
then you might find it more convenient to use the OO style:
my $xs = XML::Simple->new(
forcearray => ['hostalias', 'location', 'lab', 'addressRange'],
keyattr => { location => 'name', lab => 'name', host => 'IPaddress'},
noattr => 1,
);
my $xml = $xs->XMLin($file);
print $xs->XMLout($xml);
Regards
Grant