Re: [SOAP] Help with Soap Client
| From: | Roger Roelofs | Date: | Mon, 20 Apr 2009 03:24:39 +0000 |
| Subject: | Re: [SOAP] Help with Soap Client | ||
| References: | 1 2 3 4 | Groups: | php.soap |
| Request: | Send a blank email to php-soap+get-2924@lists.php.net to get a copy of this message | ||
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:-- Roger Roelofs Datacomp Appraisal Services rer@datacompusa.comTom, On 04/19/2009 12:58 PM, EPA WC wrote: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++ ) {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.Now I can get the soap response back with the following code, but myecho$stresults->Organization[$i]->OrganizationDescription->OrganizationFormalName; } Make sense?Roger