• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 597
  • Last Modified:

PHP Parse SOAP Data

Hello, I am having trouble parsing returned data from a soap call. I have attached a text file which is a print_r of the returned data.

I need to get the objects name, description, etc., and I am not able to. Please help!!!

Prasad
example.txt
0
iameye
Asked:
iameye
  • 7
  • 4
  • 2
1 Solution
 
sscottiCommented:
You can also look at the discussions here:

http://www.webmasterworld.com/php/3615040.htm
0
 
iameyeAuthor Commented:
Yes, these seem to deal with xml, not the stdobject array structure I posted in the file. I had already tried some of those methods anyway, like the first link that you sent just to see and most of them returned errors that the data could not be converted to a string. And yes, I tried explicitly turning it into a string.

I need someone to actually take a look, run some code against the file, see if it works, then let me know, although I am willing to try stuff people suggest to me (not tested) as well if necessary. The former is much better, however, of course!
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
iameyeAuthor Commented:
I am increasing the point value as I need this answer as quickly as possible!
0
 
Ray PaseurCommented:
I may be able to help if I can see the code you use to call the SOAP service.  I would need to be able to test it.  Please post that back here so I can access the service with my own script and I will show you what we can do with the returned information.

You might also want to contact the publisher of this information and ask if they have anything easier to use than SOAP.  Many publishers use REST calls that return XML or JSON -- much easier to use that kind of data!
0
 
iameyeAuthor Commented:
Okay, here is the code I use to call...

// submit xml to benefits calculator
      // returnFormat: 1->array, 2->html, 3->xml, 4->pdf
      $params = array(
        'xmlInput' => $xml_string,
        'returnFormat' => 1
    );
      
      $client = new SoapClient(
        "http://labs.gosmcpartners.com/CAFCA_BenefitsCalculator_WebService/BenefitsCalculator_WebService.asmx?WSDL"
    );

      //RunBenefitsCalculatorOnXML(string xmlInput, int returnFormat));
      $soapresult = $client->RunBenefitsCalculatorOnXML($params);

The comments show the choice of return data. I use the array return because I am having trouble even viewing the xml to even begin to parse it. I can't have THEM  change the choices of return format. But you can certainly try. Note, I do NOT want it as a PDF - I need to parse the return data so I can store it.

Attached is a sample xml that I submit as the xml string, which goes through fine.  The data is a sample, so no confidentiality is breached, but it IS the exact data I send to test.

Thanks for taking a look at this.

Prasad
20100916-eligibility-submit-ID78.xml
0
 
iameyeAuthor Commented:
Okay, I got most of it:

$count = 9;
$tempr = $soapresult->RunBenefitsCalculatorOnXMLResult->enc_value->BenefitsCalculatorResult;
for ($i=0; $i < $count; $i++) {
      echo($tempr[$i]->Name);
      echo "<br>";
}

I just assigned 9 to the $count variable arbitrarily since doing count($tempr->Name) doesn't work. So now I just need to figure out how to get a count. Or maybe use a while statement or something. It's late - will continue tomorrow...

Prasad
0
 
Ray PaseurCommented:
Here is how I would do it.  HTH, ~Ray
<?php // RAY_temp_iameye.php
error_reporting(E_ALL);
echo "<pre>" . PHP_EOL;



// TEST DATA DOWNLOADED FROM EE
$xml_signal = <<<XML
<?xml version="1.0" encoding="iso-8859-1"?>
<agencysystem agencysystemid="12"><household citizenshipid="1" ctresident="1" servicezip="10573" heatingpartofrent="0" outputlanguage="English"><persons><person firstname="Devaprasad" age="40" gender="f" relationshipid="39" preparefoodtogether="1" ethnicityid="2" raceid="7"><assetsummary><assetdetail assetamount="0" assetcategoryid="1"/><assetdetail assetamount="0" assetcategoryid="2"/><assetdetail assetamount="0" assetcategoryid="3"/></assetsummary><incomesummary><incomedetail incomeamount="541.2500" incomecategoryid="1"/><incomedetail incomeamount="232.0000" incomecategoryid="2"/></incomesummary><characteristics><characteristic characteristicid="4" qualifier="0"/><characteristic characteristicid="6" qualifier="0"/><characteristic characteristicid="7" qualifier="0"/><characteristic characteristicid="8" qualifier="0"/><characteristic characteristicid="9" qualifier="1"/><characteristic characteristicid="10" qualifier="0"/><characteristic characteristicid="12" qualifier="0"/><characteristic characteristicid="16" qualifier="0"/><characteristic characteristicid="17" qualifier="0"/><characteristic characteristicid="18" qualifier="0"/><characteristic characteristicid="19" qualifier="0"/><characteristic characteristicid="20" qualifier="1"/></characteristics></person><person firstname="Frank" age="30" gender="m" relationshipid="15" preparefoodtogether="0" ethnicityid="2" raceid="2"><assetsummary><assetdetail assetamount="0" assetcategoryid="1"/><assetdetail assetamount="0" assetcategoryid="2"/><assetdetail assetamount="0" assetcategoryid="3"/></assetsummary><incomesummary><incomedetail incomeamount="0" incomecategoryid="1"/><incomedetail incomeamount="0" incomecategoryid="2"/></incomesummary><characteristics><characteristic characteristicid="3" qualifier="1"/><characteristic characteristicid="4" qualifier="0"/><characteristic characteristicid="6" qualifier="0"/><characteristic characteristicid="7" qualifier="0"/><characteristic characteristicid="8" qualifier="0"/><characteristic characteristicid="9" qualifier="1"/><characteristic characteristicid="10" qualifier="0"/><characteristic characteristicid="12" qualifier="0"/><characteristic characteristicid="16" qualifier="0"/><characteristic characteristicid="17" qualifier="0"/><characteristic characteristicid="18" qualifier="0"/><characteristic characteristicid="19" qualifier="0"/></characteristics></person><person firstname="Kimberly" age="40" gender="f" relationshipid="41" preparefoodtogether="1" ethnicityid="2" raceid="1"><assetsummary><assetdetail assetamount="0" assetcategoryid="1"/><assetdetail assetamount="0" assetcategoryid="2"/><assetdetail assetamount="0" assetcategoryid="3"/></assetsummary><incomesummary><incomedetail incomeamount="0" incomecategoryid="1"/><incomedetail incomeamount="120.0000" incomecategoryid="2"/></incomesummary><characteristics><characteristic characteristicid="2" qualifier="1"/><characteristic characteristicid="4" qualifier="1"/><characteristic characteristicid="6" qualifier="0"/><characteristic characteristicid="8" qualifier="0"/><characteristic characteristicid="9" qualifier="1"/><characteristic characteristicid="10" qualifier="0"/><characteristic characteristicid="12" qualifier="0"/><characteristic characteristicid="16" qualifier="0"/><characteristic characteristicid="17" qualifier="0"/><characteristic characteristicid="18" qualifier="0"/><characteristic characteristicid="19" qualifier="0"/></characteristics></person><person firstname="Briannas" age="16" gender="f" relationshipid="34" preparefoodtogether="0" ethnicityid="2" raceid="7"><assetsummary><assetdetail assetamount="0" assetcategoryid="1"/><assetdetail assetamount="0" assetcategoryid="2"/><assetdetail assetamount="0" assetcategoryid="3"/></assetsummary><incomesummary><incomedetail incomeamount="87.6825" incomecategoryid="1"/><incomedetail incomeamount="217.5825" incomecategoryid="2"/></incomesummary><characteristics><characteristic characteristicid="2" qualifier="1"/><characteristic characteristicid="4" qualifier="1"/><characteristic characteristicid="6" qualifier="1"/><characteristic characteristicid="7" qualifier="0"/><characteristic characteristicid="9" qualifier="1"/><characteristic characteristicid="10" qualifier="0"/><characteristic characteristicid="16" qualifier="0"/><characteristic characteristicid="17" qualifier="0"/><characteristic characteristicid="18" qualifier="0"/><characteristic characteristicid="19" qualifier="0"/></characteristics></person></persons><expensesummary><expensedetail expenseamount="3948" expensecategoryid="3"/><expensedetail expenseamount="3192" expensecategoryid="5"/><expensedetail expenseamount="500" expensecategoryid="1"/></expensesummary></household></agencysystem>
XML;

// TEST CODE COPIED FROM EE - MODIFIED TO USE AND RETURN XML
// SET THE returnFormat: 1->array, 2->html, 3->xml, 4->pdf
$params
= array
( 'xmlInput' => $xml_signal
, 'returnFormat' => 3
)
;

$client
= new SoapClient
( "http://labs.gosmcpartners.com/CAFCA_BenefitsCalculator_WebService/BenefitsCalculator_WebService.asmx?WSDL"
)
;

//RunBenefitsCalculatorOnXML(string xmlInput, int returnFormat));
$soapresult = $client->RunBenefitsCalculatorOnXML($params);

// ACTIVATE THIS TO SEE THE OUTPUT -- RETURNS SOMETHING LIKE THIS:
// object(stdClass)#2 (1) {
//   ["RunBenefitsCalculatorOnXMLResult"]=>
//   string(13984) -- FOLLOWED BY THE XML STRING
// var_dump($soapresult);

// ACQUIRE THE XML STRING
$xml_return = $soapresult->RunBenefitsCalculatorOnXMLResult;

// ACTIVATE THIS TO SEE THE XML STRING
// echo htmlentities($xml_return);

// MAKE AN OBJECT SO WE CAN USE ITERATORS
// NOTE - REMOVE THE @-SIGN TO SEE WARNING MESSAGES ABOUT XMLNS
$obj = @SimpleXML_Load_String($xml_return);

// ACTIVATE THIS TO SEE THE OBJECT
// var_dump($obj);



// FIND OUT INFORMATION ABOUT THE OBJECT
$num = count($obj->program);
echo PHP_EOL . "THERE ARE $num ELEMENTS IN THE RESPONSE" . PHP_EOL;



// ITERATE OVER THE RESULTS
$eligible   = array();
$ineligible = array();
foreach ($obj->program as $program)
{
    // GET AN ELEMENT OF THE PROGRAM
    $l = (string)$program->informationlink;

    // GET ATTRIBUTES OF THE PROGRAM
    $n = (string)$program["name"];
    $c = (string)$program["category"];
    $e = (string)$program["iseligible"];
    $d = (string)$program["displayifineligible"];

    // CREATE A LINK
    $u = $n;
    if (!empty($l))
    {
        $u = '<a target="_blank" href="' . $l . '">' . $n . '</a>';
    }

    // CREATE DISPLAY INFORMATION FOR THIS PROGRAM
    $str = PHP_EOL . $u . ' ';
    if ( strtoupper($d) == 'TRUE')
    {
        $str .= $c;
    }
    else
    {
        $str .= 'REDACTED';
    }

    // PUT THE DISPLAY INFORMATION IN THE CORRECT ARRAY
    if ( strtoupper($e) == 'TRUE')
    {
        $eligible[] = $str;
    }
    else
    {
        $ineligible[] = $str;
    }
}

// SHOW WHAT WE FOUND
echo PHP_EOL . 'ELIGIBLE';
foreach ($eligible as $str) { echo $str; }

echo PHP_EOL;

echo PHP_EOL . 'INELIGIBLE';
foreach ($ineligible as $str) { echo $str; }

Open in new window

0
 
iameyeAuthor Commented:
Wow - very nice! Will try this out first thing tomorrow morning!
0
 
Ray PaseurCommented:
Try it without the @-sign on line 45.  You might want to tell the XML publisher about the warning messages!

Best regards, ~Ray
0
 
iameyeAuthor Commented:
Thanks Ray!
0
 
iameyeAuthor Commented:
Very thorough - exactly what was requested.
0
 
Ray PaseurCommented:
Glad to help!  Best of luck with it, ~Ray
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 7
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now