Link to home
Start Free TrialLog in
Avatar of Geoff Millikan
Geoff MillikanFlag for United States of America

asked on

PHP5 > Easiest way to parse SOAP/XML string?

I'm getting the attached SOAP/XML string back from an API.  I'm looking for the easiest/best way of parsing it into an array/object so I can access the data.  I tried using SimpleXMLElement() but it wasn't able to parse it, it just returned a blank - no errors, no nothing.
<?php
$xmlData = new SimpleXMLElement($the_attached_data);
echo '<pre>';
var_dump($xmlData);
//Returns:  object(SimpleXMLElement)#1 (0) {}
?>

Open in new window

SOAP-XML-String.txt
Avatar of Roger Baklund
Roger Baklund
Flag of Norway image

If you use specialized functions for SOAP, it will be easier. There is a builtin soapclient class:

http://php.net/manual/en/class.soapclient.php

And this is a good open source (LGPL) alternative:

http://sourceforge.net/projects/nusoap/
http://www.scottnichol.com/nusoapintro.htm
Try this and see if you can't find more of the object.

HTH, ~Ray
<?php
$xmlData = SimpleXML_Load_String($the_attached_data);
echo '<pre>';
var_dump($xmlData);
//Returns:  object(SimpleXMLElement)#1 (0) {}
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Geoff Millikan

ASKER

cxr: Although you'd think that the SoapClient() would be cool, and believe me I wish it were, it is not.  In fact, SOAP in general is yucky.  SOAP is like Brussels sprouts - you can put as much cheese topping on them as you like, but they still are not very good.  Which is probably why you just gave me the link to the RTFM on the SoapClient() instead of providing an example of how to do it.  Not trying to give you a hard time, just driving home the point that nobody wants to do SOAP.  Again, for example: https://www.experts-exchange.com/questions/24291253/PHP5-Using-SoapClient-to-make-request.html

Ray, your solution works.  Obviously I'm enjoying the "RAY_temp_hates_soap.php" name.
How did you know to exchange 'soap:' and 'soap_'?  Experience?
Ray, saw your name on the PHP boards at the link below.  Never realized you were famous... ;-)   Thanks for your help on so many questions.

http://www.php.net/manual/en/function.base-convert.php
@t1shopper: Thanks for the points!

"How did you know to exchange 'soap:' and 'soap_'?  Experience?" Yup, nothing more!

Regarding the PHP.net post, I have made several of those over the years (varying in importance and quality, to be sure) and have found the PHP community to be amazingly responsive and helpful.  Several years ago I posted an algorithm to determine the date of Easter and today it is a built-in function in PHP:
http://us3.php.net/manual/en/function.easter-date.php

Having said that, I find the back-and-forth dialog here at EE to be a great learning tool.  Glad I was able to be helpful to you here.

Best, ~Ray
Nicely done.   We wouldn't be where we are today without the PHP help we've received from you and others here at EE.