2

I'm working with a wsdl file, and learning quite a lot from the whole process.

I'm instantiating the SoapClient:

$webservice = new SoapClient("mainwsdl.wsdl");
var_dump($webservice->AccountsGetXML()); 

Below is the response, and I'm still a little new with parsing data.

object(stdClass)#2 (3) {
  ["AccountsGetXMLResult"]=>
  object(stdClass)#3 (1) {
    ["any"]=>
    string(391) "<AccountsWSDS xmlns=""><ERRORS><ERROR_ID>1</ERROR_ID><TABLE_NAME>Accounts</TABLE_NAME><TABLE_ID>NoID</TABLE_ID><ROW_ID>-1</ROW_ID><COLUMN_ID>EXCEPTION</COLUMN_ID><ERROR_TYPE>E</ERROR_TYPE><ERROR_CODE>0</ERROR_CODE><ERROR_TEXT>Error connecting to database - please contact ABC Customer Services.  Msg: Object reference not set to an instance of an object.</ERROR_TEXT></ERRORS></AccountsWSDS>"
  }
  ["rowCount"]=>
  NULL
  ["pageCount"]=>
  NULL
}

I haven't played with object(stdClass) responses before. Or if I have I've been oblivious to it.

I figure I need to parse ["AccountsGetXMLResult"] for specific information, but also ["rowCount"] and ["pageCount"].

I'm confused what the #2 (3) is all about.

Anyway, here's my attempt at parsing the data. I started with the AccountsGetXMLResult:

echo $webservice->AccountsGetXMLResult;

Here's what I got back.
PHP Notice: Undefined property: SoapClient::$AccountsGetXMLResult in /apache/test.php on line 23

So clearly I'm in need of help with dissecting responses.

1
  • 1
    The #2 (3) means that it's the second instance of stdClass for that process and that there are three properties of the object. Commented May 22, 2012 at 1:19

2 Answers 2

1

$webservice->AccountsGetXML() returns an object of type stdClass with the properties you see in the var dump. stdClass is just an "empty placeholder class" without any predefined properties or methods of its own. To access the properties you see, work on the return value of $webservice->AccountsGetXML():

$obj = $webservice->AccountsGetXML();
var_dump($obj->AccountsGetXMLResult);
var_dump($obj->AccountsGetXMLResult->any);

This also works like this:

echo $webservice->AccountsGetXML()->AccountsGetXMLResult->any;
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

$result = json_decode(json_encode(simplexml_load_string($webservice->AccountsGetXML()->AccountsGetXMLResult->any)),TRUE);

print_r($result);

2 Comments

I know he isn't using JSOn, this just converts the response to JSOn then immediately converts it back to a PHP array allowing him to access it as a PHP array. It works.
@ClintDecker Hey man this worked great for me. Nothing else seems to be working. It converts the SOAP XML perfectly into a PHP array, so thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.