我已经转储了以下 XML 结构。
$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'
}
}
}
};
我不知道如何从value1
和value2
属性中提取值。我尝试使用XML::Simple,但以哈希值而不是属性结束。
my $doclist = XMLin('my file.xml');
my $docvalues = $doclist->{docvalues};
my @docvalue = $docvalues->{docvalue};
my ($v1, $v2, $v3) = @_;
foreach my $doc_value (@docvalue) {
my @doc = $doc_value->{doc};
foreach my $values (@doc) {
$v1 = $values->{'value1'};
}
}