I can successfully make a SOAP request and dump the response:
my $soap = SOAP::Lite -> proxy($url); my $res = $soap->$method(@data); use Data::Dumper; print Dumper($res)
But, after spending hours trying to decipher the documentation of SOAP::Lite (and ::SOM) I cannot for the life of me figure out how to access (as variables) some of the sub elements of the data that is returned. I'd like to code something similar to the following pseudo code:
Foreach campaign in campaigns { print $campaign{Name}; print $campaign{Cost}; print $campaign{Sessions}{Number}; print $campaign{Sessions}{TotalVisits}; }
out of the following sample data (in XML for brevity)
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/env +elope/"> <SOAP-ENV:Body> <APIResponse> <ClickFraudReport> <Name>Click Fraud Report</Name> <TimeRange>Thursday, November 23, 2006 - Wednesday, November 2 +9, 2006</TimeRange> <Campaigns> <Campaign> <Name>Google 140</Name> <Cost>$330.14</Cost> <LandingPage>/?source=29938</LandingPage> <Keywords>probability, stasticial analysis</Keywords> <Headline>Special Headline</Headline> <Criterion>http://www.mywebsite.com?source=29938</Criterio +n> <Sessions> <Number>230</Number> <TotalVisits>7733</TotalVisits> <Changed>0</Changed> <OldNumber>267</OldNumber> <OldTotalVisits>10249</OldTotalVisits> </Sessions> </Campaign> <Campaign> <Name>Google 28</Name> <Cost>$566.02</Cost> <LandingPage>/?source=29033</LandingPage> <Keywords>caution, long tail</Keywords> <Headline>Even Better Headline</Headline> <Criterion>http://www.mywebsite.com?source=29033</Criterio +n> <Sessions> <Number>837</Number> <TotalVisits>4599</TotalVisits> <Changed>0</Changed> <OldNumber>112</OldNumber> <OldTotalVisits>10883</OldTotalVisits> </Sessions> </Campaign> </Campaigns> </ClickFraudReport> </APIResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
Thanks for any help.

In reply to How to access elements that SOAP::Lite Returns by Anonymous Monk

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.