Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP5 > Easiest way to parse SOAP/XML string?

Posted on 2009-04-05
8
Medium Priority
?
702 Views
Last Modified: 2013-11-18
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
0
Comment
Question by:Geoff Millikan
  • 4
  • 3
8 Comments
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24073163
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
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 24073253
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

0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 24073278
Better yet, try some code that actually got tested!
;-)


<?php // RAY_temp_hates_soap.php
error_reporting(E_ALL);
echo "<pre>";
 
// TEST DATA
$xml = ' [ INSERT YOUR SOAP XML STRING HERE] ';
// END TEST DATA
 
// MUNG THE TEST DATA
$xml = str_replace('soap:', 'soap_', $xml);
 
// MAKE AN OBJECT
$obj = SimpleXML_Load_String($xml);
var_dump($obj);

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:Geoff Millikan
ID: 24073398
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: http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_24291253.html

Ray, your solution works.  Obviously I'm enjoying the "RAY_temp_hates_soap.php" name.
0
 

Author Comment

by:Geoff Millikan
ID: 24073404
How did you know to exchange 'soap:' and 'soap_'?  Experience?
0
 

Author Comment

by:Geoff Millikan
ID: 24101872
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
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 24108122
@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
0
 

Author Comment

by:Geoff Millikan
ID: 24108231
Nicely done.   We wouldn't be where we are today without the PHP help we've received from you and others here at EE.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This article discusses how to implement server side field validation and display customized error messages to the client.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question