I'm trying to handle the data coming from the Adwords API with XML::Simple, which seems to be a decent choice for it, but I can't seem to grab the values that I need, which are just so deep into the XML. I'm not sure where I'm wrong, but maybe you can help:
#!/usr/bin/perl -w use strict; use XML::Simple; use Data::Dumper; my $content = XMLin(qq| <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envel +ope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http:// +www.w3.org/2001/XMLSchema-instance"> <soapenv:Header> <responseTime soapenv:actor="http://schemas.xmlsoap.org/soap/actor/n +ext" soapenv:mustUnderstand="0" xmlns="https://adwords.google.com/api +/adwords/v5">124</responseTime> <operations soapenv:actor="http://schemas.xmlsoap.org/soap/actor/nex +t" soapenv:mustUnderstand="0" xmlns="https://adwords.google.com/api/a +dwords/v5">1</operations> <units soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" so +apenv:mustUnderstand="0" xmlns="https://adwords.google.com/api/adword +s/v5">25</units> <requestId soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next +" soapenv:mustUnderstand="0" xmlns="https://adwords.google.com/api/ad +words/v5">123</requestId> </soapenv:Header> <soapenv:Body> <getKeywordVariationsResponse xmlns="https://adwords.google.com/api/ +adwords/v5"> <getKeywordVariationsReturn> <moreSpecific> <text>web content managment</text> <language>en</language> <advertiserCompetitionScale>3</advertiserCompetitionScale> <searchVolumeScale>1</searchVolumeScale> </moreSpecific> <moreSpecific> <text>web based content management</text> <language>en</language> <advertiserCompetitionScale>5</advertiserCompetitionScale> <searchVolumeScale>1</searchVolumeScale> </moreSpecific> <additionalToConsider> <text>3.14</text> <language>en</language> <advertiserCompetitionScale>3</advertiserCompetitionScale> <searchVolumeScale>2</searchVolumeScale> </additionalToConsider> <additionalToConsider> <text>babinet's</text> <language>en</language> <advertiserCompetitionScale>2</advertiserCompetitionScale> <searchVolumeScale>0</searchVolumeScale> </additionalToConsider> </getKeywordVariationsReturn> </getKeywordVariationsResponse> </soapenv:Body> </soapenv:Envelope> |); print "... $content->{'soapenv:Envelope'}{'soapenv:Body'}{'getKeywordV +ariationsResponse'}{'getKeywordVariationsReturn'}{'moreSpecific'}[0]- +>{'text'} ...\n"; #print Dumper(\$content);
This returns me nothing, and I even get the fun uninitialized statement:
Use of uninitialized value in concatenation (.) or string at xmlparser +.pl line 54.
Any ideas? Obviously I need what's in the text, advertiserCompetitionScale, and searchVolume tags, and I need to iterate through each occurrence. Any ideas?


Michael

In reply to Trouble Getting Deep Into a Hash from XML::Simple by inblosam

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.