I'm trying to build XML that looks like this using XML::Simple:
<response>
<device>
<interface>
<mh>0x123abc</mh>
<portname>Gi1/1</portname>
</interface>
<interface>
<mh>0x123abc</mh>
<portname>Gi1/1</portname>
</interface>
<interface>
<mh>0x123abc</mh>
<portname>Gi1/1</portname>
</interface>
</device>
</response>
I'm finding XML::Simple very difficult to behave like I want, so I tried feeding it it's own medicine:
$req = <<EOF;
<response>
<device>
<interface>
<mh>0x123abc</mh>
<portname>Gi1/1</portname>
</interface>
<interface>
<mh>0x123abc</mh>
<portname>Gi1/1</portname>
</interface>
<interface>
<mh>0x123abc</mh>
<portname>Gi1/1</portname>
</interface>
</device>
</response>
EOF
print Dumper(XML::Simple::XMLin($req));
yields:
$VAR1 = {
'device' => {
'interface' => [
{
'portname' => 'Gi1/1',
'mh' => '0x123abc'
},
{
'portname' => 'Gi1/1',
'mh' => '0x123abc'
},
{
'mh' => '0x123abc',
'portname' => 'Gi1/1'
}
]
}
};
If I feed that back into XML::Simple and print it:
my $xml = XML::Simple::XMLout($VAR1, RootName => "response");
print $xml;
I get this, which doesn't match what I sent it in the first place:
<response>
<device>
<interface mh="0x123abc" portname="Gi1/1" />
<interface mh="0x123abc" portname="Gi1/1" />
<interface mh="0x123abc" portname="Gi1/1" />
</device>
</response>
How do I tell XML::Simple to treat a node as a node and not an attribute?