Solved

PHP5 > Easiest way to parse SOAP/XML string?

Posted on 2009-04-05
8
697 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 110

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 110

Accepted Solution

by:
Ray Paseur earned 500 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
Independent Software Vendors: 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!

 

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 110

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
This article discusses how to implement server side field validation and display customized error messages to the client.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 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