[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Parse Soap Response with SimpleXML problem

Posted on 2010-04-02
1
Medium Priority
?
1,195 Views
Last Modified: 2013-11-18
So I am making a soap call in PHP using fopen.  I cannot figure out how to parse to a specific value in the soap env response to save my life.

I have been Topekaing( errr Googleing) this for hours and have tried everything from declare namespaces to removing the colons etc...

Any help woudl be appreciated!
//soap req env

$contents = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <payRequest>
      <actionType>PAY</actionType>
      <cancelUrl>http://myCancelUrl.com</cancelUrl>
      <currencyCode>USD</currencyCode>
      <returnUrl>http://myReturnUrl.com</returnUrl>
      <receiverList>
        <receiver>
          <amount>10</amount>
          <email>newsel_1245945819_biz@leezacentral.com</email>
        </receiver>
      </receiverList>
      <requestEnvelope>
        <errorLanguage>en_US</errorLanguage>
      </requestEnvelope>
    </payRequest>
  </soapenv:Body>
</soapenv:Envelope>';

//Soap Response

<?xml version='1.0' encoding='utf-8'?>
	<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
		<soapenv:Header />
		<soapenv:Body>
			<ns2:PayResponse xmlns:ns2="http://svcs.paypal.com/types/ap">
				<responseEnvelope>
					<timestamp>2010-04-02T10:07:57.246-07:00</timestamp>
					<ack>Success</ack>
					<correlationId>7fe65d08e725a</correlationId>
					<build>1238639</build>
				</responseEnvelope>
				<payKey>AP-32D204908S5562638</payKey>
				<paymentExecStatus>CREATED</paymentExecStatus>
			</ns2:PayResponse>
		</soapenv:Body>
	</soapenv:Envelope>

Open in new window

0
Comment
Question by:lharrispv
1 Comment
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 29507220
This issue is discussed here:
http://www.webmasterkitchen.com/article/problems-with-php-simplexml-soap-results/
http://dd32.id.au/2007/09/29/php-simplexml-soap/

Basically, they are getting rid of the colon between the namespace and the tag name:
$xmlString = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $response);

then they load the "clean" xml (which is now in $xmlString) into simple xml
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

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.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

607 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