Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8143641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:10:15+00:00 2026-06-06T13:10:15+00:00

I have dumped the following XML structure. $VAR1 = { ‘events’ => {}, ‘docvalues’

  • 0

I have dumped the following XML structure.

$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'
            }
        }
    }
};

I’m stuck with how to extract the values from the value1 and value2 attributes. I tried using XML::Simple, but ending up with hash values rather than attributes.

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'};
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T13:10:19+00:00Added an answer on June 6, 2026 at 1:10 pm

    It’s rather straight forward, but a little long.

    foreach my $country (keys %{ $VAR1->{'docvalues'}->{'docvalue'} } ) {
      print "Country: $country\n";
      foreach my $doc (keys %{ $VAR1->{'docvalues'}->{'docvalue'}->{$country}->{'doc'} }) {
        print "doc: $doc\n";
        print "value1: " . $VAR1->{'docvalues'}->{'docvalue'}->{$country}->{'doc'}->{$doc}->{'value1'} . "\n";
        print "value2: " . $VAR1->{'docvalues'}->{'docvalue'}->{$country}->{'doc'}->{$doc}->{'value2'} . "\n";
      }
    }
    

    Output:

    Country: ENGLAND
    doc: England
    value1: 0.70312
    value2: 52.16045
    doc: New England District
    value1: 151.65
    value2: -30.51667
    Country: MS
    doc: Mississip pi
    value1: 31.64850330352783
    value2: -91.29143524169922
    doc: Mississippi County
    value1: -89.31674
    value2: 36.81672
    

    The trick is to check where things reoccur. It’s clear that there seem to be several countries, so we need a loop for those. Then each country has something called doc with two regions in it. We have to loop over these because they hold the value1 and value2.


    Reindenting to increase redability and zooming out in the text editor (smaller font) helped me.

    my $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'
          }
        }
      }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following file dumped daily into one of our online directories: dat-part2-489359-43535-toward.txt
I have the following XML file: <?xml version='1.0'?> <preferences> <font role=console> <fname>Courier</fname> <size>9</size> </font>
I have the following test code use Data::Dumper; my $hash = { foo =>
I have a dict object. I dumped the data using this: for alldata in
I have following workflow div on the page is used on users operation request
I have the following two mySQL tables with the 'child' table having a DELETE
I have the following: ASP.NET website using the 3.5 framework One folder that contains
I have the following code: Dim cn As Object Dim rs As Object Dim
Right now I have the following in my Vagrantfile: config.vm.provision :chef_solo do |chef| chef.cookbooks_path
I have the following code and it is the nightmare that I feared when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.