Subject: | attribute name changed |
Environment:
XML::Simple version 2.09 or 1.06 (I happen to have both to hand)
HP-UX 11.00
Perl v5.6.1 built for PA-RISC1.1
Source XML (test.xml):
<opt>
<location>
<name>Location1</name>
<lab>
<name>lab1</name>
<host>
<site>4</site>
<hostname>s005b01lm</hostname>
<gateway>10.225.5.1</gateway>
<subnetMask>255.255.255.192</subnetMask>
<IPaddress>10.225.5.39</IPaddress>
</host>
<host>
<site>4</site>
<hostname>s006b01lm</hostname>
<gateway>10.225.6.1</gateway>
<subnetMask>255.255.255.192</subnetMask>
<IPaddress>10.225.6.39</IPaddress>
</host>
</lab>
</location>
</opt>
Perl Source:
#!/usr/bin/perl -w
use XML::Simple;
use strict;
use warnings;
my $file = 'test.xml';
my $xml = XMLin($file, forcearray => ['hostalias', 'location', 'lab', 'addressRange'], keyattr => { location => 'name', lab => 'name', host => 'IPaddress'});
print XMLout($xml, noattr => 1) . "\n";
Output :
<opt>
<location>
<lab>
<host>
<site>4</site>
<hostname>s005b01lm</hostname>
<gateway>10.225.5.1</gateway>
<subnetMask>255.255.255.192</subnetMask>
<name>10.225.5.39</name>
</host>
<host>
<site>4</site>
<hostname>s006b01lm</hostname>
<gateway>10.225.6.1</gateway>
<subnetMask>255.255.255.192</subnetMask>
<name>10.225.6.39</name>
</host>
<name>lab1</name>
</lab>
<name>Location1</name>
</location>
</opt>
Problem:
All tags <IPaddress></IPaddress> have been changed to <name></name> and I can't see why.
It's not a big problem but it looks like a bug.