Thread: Xml referencing

    #1
  1. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,464
    Rep Power
    594

    Xml referencing


    I always seem to get confused when referencing hashes. I am using Google maps to return an xml result. However, I am having trouble figuring out how to reference the returned elements. A Dumper($result) of the returned xml looks like this:
    Code:
    $VAR1 = bless( {
                     '_protocol' => 'HTTP/1.1',
                     '_content' => '<?xml version="1.0" encoding="UTF-8"?>
    <DistanceMatrixResponse>
     <status>OK</status>
     <origin_address>Loganville, GA 30052, USA</origin_address>
     <destination_address>Hendersonville, NC 28791, USA</destination_address>
     <destination_address>Denton, TX 76209, USA</destination_address>
     <row>
      <element>
       <status>OK</status>
       <duration>
        <value>11493</value>
        <text>3 hours 12 mins</text>
       </duration>
       <distance>
        <value>278717</value>
        <text>173 mi</text>
       </distance>
      </element>
      <element>
       <status>OK</status>
       <duration>
        <value>45246</value>
        <text>12 hours 34 mins</text>
       </duration>
       <distance>
        <value>1374523</value>
        <text>854 mi</text>
       </distance>
      </element>
     </row>
    </DistanceMatrixResponse>
    ',
                     '_rc' => '200',
                     '_headers' => bless( {
                                            'connection' => 'close',
                                            'client-response-num' => 1,
                                            'cache-control' => 'public, max-age=86400',
                                            'date' => 'Thu, 11 Jul 2013 09:56:38 GMT',
                                            'vary' => 'Accept-Language',
                                            'client-peer' => '74.125.129.95:80',
                                            '::std_case' => {
                                                              'client-date' => 'Client-Date',
                                                              'x-frame-options' => 'X-Frame-Options',
                                                              'client-response-num' => 'Client-Response-Num',
                                                              'x-xss-protection' => 'X-XSS-Protection',
                                                              'client-peer' => 'Client-Peer'
                                                            },
                                            'client-date' => 'Thu, 11 Jul 2013 09:56:38 GMT',
                                            'x-frame-options' => 'SAMEORIGIN',
                                            'content-type' => 'application/xml; charset=UTF-8',
                                            'x-xss-protection' => '1; mode=block',
                                            'server' => 'mafe',
                                            'expires' => 'Fri, 12 Jul 2013 09:56:38 GMT'
                                          }, 'HTTP::Headers' ),
                     '_msg' => 'OK',
                     '_request' => bless( {
                                            '_content' => '',
                                            '_uri' => bless( do{\(my $o = 'http://maps.googleapis.com/maps/api/distancematrix/xml?sensor=false&units=imperial&origins=30052&destinations=28791%7C76209')}, 'URI::http' ),
                                            '_headers' => bless( {
                                                                   'user-agent' => 'libwww-perl/6.05'
                                                                 }, 'HTTP::Headers' ),
                                            '_method' => 'GET',
                                            '_uri_canonical' => bless( do{\(my $o = 'http://maps.googleapis.com/maps/api/distancematrix/xml?sensor=false&units=imperial&origins=30052&destinations=28791%7C76209')}, 'URI::http' )
                                          }, 'HTTP::Request' )
                   }, 'HTTP::Response' );
    I want to print the <status> element so I do this:
    Code:
    print($result->{DistanceMatrixResponse}{status}."\n");
    Which apparently is wrong:

    Use of uninitialized value in concatenation (.) or string

    What is the syntax I am supposed to be using? TIA.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,464
    Rep Power
    594
    Never mind. Dopey me forgot to parse the content into XML. Sorry.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo