Solved

PHP5 > Easiest way to parse SOAP/XML string?

Posted on 2009-04-05
8
691 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 108

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 108

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
 

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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 108

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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now