Re: Help with Soap Client

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tom,

You would use the same kind of code you would use to iterate over any php object. I suppose if you were looking to draw a map you could write a callback that gets called for particularly named elements. The code that follows is off the top of my head and untested, but it might give you an idea.

function doRealWork(item) {
    // whatever
}

function recurse($data, $find, $callback) {
    $type = gettype($data);
    if (( $type == "array" ) || ( $type == "object" )) {
        foreach ( $type as $key => $val ) {
            if ( $key == $find ) $callback($val);
            elseif ( ! is_scalar($val ) recurse($val, $find, $callback);
        }
    }
}

recurse($stresults, "elementToFind", "doRealWork");


On 04/19/2009 08:25 PM, EPA WC wrote:
Thanks Roger. Yes I figured it out too once I changed my mindset from
simplexml to object. But I'd like to see some generic code that can
take xml schema and extract data needed from soap response objects.

Tom

On Sun, Apr 19, 2009 at 6:20 PM, Roger Roelofs<rer@datacompusa.com>  wrote:
Tom,

On 04/19/2009 12:58 PM, EPA WC wrote:
Now I can get the soap response back with the following code, but my
new problem is how I can parse out information from returned stdClass
Object. Originally I thought about using simplexml to get what I need,
but it didn't work since the returned results are in stdClass Objects.
I also listed the response I got from this code.

No parsing is required.  That's kind of the point of using the soap client.
  You get back a php object with all the data you would normaly have to parse
out of the xml yourself.  For example, to display the organization names in
a list, you just walk the array

for ( $i=0; $i<  count($stresults->Organization); $i++ ) {
    echo
$stresults->Organization[$i]->OrganizationDescription->OrganizationFormalName;
}

Make sense?

Roger
--
Roger Roelofs
Datacomp Appraisal Services
rer@datacompusa.com



--
PHP Soap Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Kernel Newbies]     [PHP Database]     [Yosemite]

  Powered by Linux