XML::Simple を使用して、次のような XML を構築しようとしています。
<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>
私は、XML::Simple を思い通りに振る舞うのが非常に難しいと感じているので、それを自分の薬として食べさせてみました:
$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));
収量:
$VAR1 = {
'device' => {
'interface' => [
{
'portname' => 'Gi1/1',
'mh' => '0x123abc'
},
{
'portname' => 'Gi1/1',
'mh' => '0x123abc'
},
{
'mh' => '0x123abc',
'portname' => 'Gi1/1'
}
]
}
};
それを XML::Simple に戻して出力すると:
my $xml = XML::Simple::XMLout($VAR1, RootName => "response");
print $xml;
これは、最初に送信したものと一致しません。
<response>
<device>
<interface mh="0x123abc" portname="Gi1/1" />
<interface mh="0x123abc" portname="Gi1/1" />
<interface mh="0x123abc" portname="Gi1/1" />
</device>
</response>
ノードを属性ではなくノードとして扱うように XML::Simple に指示するにはどうすればよいですか?