Solved

PHP5 > Easiest way to parse SOAP/XML string?

Posted on 2009-04-05
8
698 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

628 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