How do I extract attributes in a data structure from XML::Simple?

DillonT

New Member
I have dumped the following XML structure.\[code\]$VAR1 = { 'events' => {}, 'docvalues' => { 'docvalue' => { 'ENGLAND' => { 'doc' => { 'England' => { 'value1' => '0.70312', 'value2' => '52.16045', 'type' => 'other', 'rank' => '21' }, 'New England District' => { 'value1' => '151.65', 'value2' => '-30.51667', 'type' => 'other', 'rank' => '18' } }, 'id' => 'rb5' }, 'MS' => { 'contains' => 'rb7', 'abbrev-for' => 'Mississippi', 'doc' => { 'Mississip pi' => { 'value1' => '31.64850330352783', 'value2' => '-91.29143524169922', 'type' => 'other', 'rank' => '8' }, 'Mississippi County' => { 'value1' => '-89.31674', 'value2' => '36.81672', 'type' => 'other', 'rank' => '6' } }, 'id' => 'rb9' } } }};\[/code\]I'm stuck with how to extract the values from the \[code\]value1\[/code\] and \[code\]value2\[/code\] attributes. I tried using XML::Simple, but ending up with hash values rather than attributes.\[code\]my $doclist = XMLin('my file.xml');my $docvalues = $doclist->{docvalues};my @docvalue = http://stackoverflow.com/questions/11209513/$docvalues->{docvalue};my ($v1, $v2, $v3) = @_;foreach my $doc_value (@docvalue) { my @doc = $doc_value->{doc}; foreach my $values (@doc) { $v1 = $values->{'value1'}; }}\[/code\]
 
Back
Top