Hi,
I am using XML::Simple to parse a XML file. The output is a hash.(using Data::Dumper)
Sample code , XML file are given below with output.
Perl code:
use XML::Simple;
use Data::Dumper;
$xml = new XML::Simple;
$data = $xml->XMLin("spam.xml");
print Dumper($data);
XML file contents (input to parser)::
<Attach_request>
<Protocol_discriminator>
<name> Protocol_discriminator </name>
<attribute> Mandatory </attribute>
<type> nibble </type>
<value> 7 </value>
<min> 0 </min>
<max> F </max>
</Protocol_discriminator>
<Security_header>
<name> Security_header </name>
<attribute> Mandatory </attribute>
<type> nibble </type>
<value> 7 </value>
<min> 0 </min>
<max> F </max>
</Security_header>
<Security_header1>
<name> Security_header </name>
<attribute> Mandatory </attribute>
<type> nibble </type>
<value> 7 </value>
<min> 0 </min>
<max> F </max>
</Security_header1>
<Security_header2>
<name> Security_header </name>
<attribute> Mandatory </attribute>
<type> nibble </type>
<value> 7 </value>
<min> 0 </min>
<max> F </max>
</Security_header2>
<Security_header3>
<name> Security_header </name>
<attribute> Mandatory </attribute>
<type> nibble </type>
<value> 7 </value>
<min> 0 </min>
<max> F </max>
</Security_header3>
</Attach_request>
Output::
$VAR1 = {
'Security_header3' => {
'attribute' => ' Mandatory ',
'min' => ' 0 ',
'value' => ' 7 ',
'max' => ' F ',
'name' => ' Security_header ',
'type' => ' nibble '
},
'Protocol_discriminator' => {
'attribute' => ' Mandatory ',
'min' => ' 0 ',
'value' => ' 7 ',
'max' => ' F ',
'name' => ' Protocol_discriminator ',
'type' => ' nibble '
},
'Security_header2' => {
'attribute' => ' Mandatory ',
'min' => ' 0 ',
'value' => ' 7 ',
'max' => ' F ',
'name' => ' Security_header ',
'type' => ' nibble '
},
'Security_header' => {
'attribute' => ' Mandatory ',
'min' => ' 0 ',
'value' => ' 7 ',
'max' => ' F ',
'name' => ' Security_header ',
'type' => ' nibble '
},
'Security_header1' => {
'attribute' => ' Mandatory ',
'min' => ' 0 ',
'value' => ' 7 ',
'max' => ' F ',
'name' => ' Security_header ',
'type' => ' nibble '
}
};
My other question is::
- Is there any way i can manintain the order of the output, the same i gave in the input XML file ??