Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

PHP XML SOAP  - How to parse the Response?

Posted on 2012-08-25
7
Medium Priority
?
1,377 Views
Last Modified: 2012-08-25
Hi,

Firstly thank you for taking a look at my question your expert advice is very much appreciated.

I have the following response:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><GetPaymentsResponse xmlns="https://somedomain/"><GetPaymentsResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Data><Payment><BankFailedReason/><BankReceiptID>362021</BankReceiptID><BankReturnCode>O</BankReturnCode><CustomerName>JG testing</CustomerName><DebitDate>2012-08-24T00:00:00</DebitDate><EzidebitCustomerID/><InvoiceID>0</InvoiceID><PaymentAmount>100</PaymentAmount><PaymentID>WEB51409</PaymentID><PaymentMethod>CR</PaymentMethod><PaymentReference>JG123</PaymentReference><PaymentSource>WEB</PaymentSource><PaymentStatus>P</PaymentStatus><ScheduledAmount>97.42</ScheduledAmount><SettlementDate i:nil="true"/><TransactionFeeClient>0</TransactionFeeClient><TransactionFeeCustomer>2.58</TransactionFeeCustomer><TransactionTime>2012-08-25T10:38:00</TransactionTime><YourGeneralReference/><YourSystemReference/></Payment></Data><Error>0</Error><ErrorMessage i:nil="true"/></GetPaymentsResult></GetPaymentsResponse></s:Body></s:Envelope>

and the way i normally would do it in Simple_XML_response doesn't work as the soap is shortened to simply s:

do I still use simple_XML or is there another way?  your help/advice is much appreciated.

many thanks!
0
Comment
Question by:mavmanau
  • 4
  • 3
7 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38332326
Please use the code snippet feature to post the XML strings - it is much easier to read that way.
0
 

Author Comment

by:mavmanau
ID: 38332333
hi,

sorry, how is that?
<pre>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body><GetPaymentsResponse xmlns="https://px.ezidebit.com.au/">
<GetPaymentsResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Data><Payment>
<BankFailedReason/>
<BankReceiptID>362021</BankReceiptID>
<BankReturnCode>O</BankReturnCode>
<CustomerName>JG testing</CustomerName><DebitDate>2012-08-24T00:00:00</DebitDate>
<CustomerID/>
<InvoiceID>0</InvoiceID>
<PaymentAmount>100</PaymentAmount>
<PaymentID>WEB51409</PaymentID>
<PaymentMethod>CR</PaymentMethod>
<PaymentReference>JG123</PaymentReference>
<PaymentSource>WEB</PaymentSource>
<PaymentStatus>P</PaymentStatus>
<ScheduledAmount>97.42</ScheduledAmount>
<SettlementDate i:nil="true"/>
<TransactionFeeClient>0</TransactionFeeClient><TransactionFeeCustomer>2.58</TransactionFeeCustomer><TransactionTime>2012-08-25T10:38:00</TransactionTime>
<YourGeneralReference/><YourSystemReference/>
</Payment>
</Data>
<Error>0</Error>
<ErrorMessage i:nil="true"/>
</GetPaymentsResult>
</GetPaymentsResponse>
</s:Body>
</s:Envelope>

Open in new window

0
 

Author Comment

by:mavmanau
ID: 38332336
i can grab the individual parts once I know how to access them just having  a few issues getting the $obj->xxxxx as $data correct, unless I am better off going a different way to the simpleXML method?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38332340
This will throw some warnings because it appears that some of the information in the XML string has been blotted out, but it illustrates a way that you can deal with the namespace issue in a quick and easy way.  HTH, ~Ray

<?php // RAY_temp_mavmanau.php
error_reporting(E_ALL);
echo '<pre>';

// XML TEST DATA FROM THE POST AT EE
$xml = <<<XML
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><GetPaymentsResponse xmlns="https://somedomain/"><GetPaymentsResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Data><Payment><BankFailedReason/><BankReceiptID>362021</BankReceiptID><BankReturnCode>O</BankReturnCode><CustomerName>JG testing</CustomerName><DebitDate>2012-08-24T00:00:00</DebitDate><EzidebitCustomerID/><InvoiceID>0</InvoiceID><PaymentAmount>100</PaymentAmount><PaymentID>WEB51409</PaymentID><PaymentMethod>CR</PaymentMethod><PaymentReference>JG123</PaymentReference><PaymentSource>WEB</PaymentSource><PaymentStatus>P</PaymentStatus><ScheduledAmount>97.42</ScheduledAmount><SettlementDate i:nil="true"/><TransactionFeeClient>0</TransactionFeeClient><TransactionFeeCustomer>2.58</TransactionFeeCustomer><TransactionTime>2012-08-25T10:38:00</TransactionTime><YourGeneralReference/><YourSystemReference/></Payment></Data><Error>0</Error><ErrorMessage i:nil="true"/></GetPaymentsResult></GetPaymentsResponse></s:Body></s:Envelope>
XML;

// FUNCTION TO MUNG THE XML
function mungXML($xml)
{
    // A REGULAR EXPRESSION TO MUNG THE XML
	$rgx
	= '#'           // REGEX DELIMITER
	. '('           // GROUP PATTERN 1
	. '\<'          // LOCATE A LEFT WICKET
	. '/{0,1}'      // MAYBE FOLLOWED BY A SLASH
	. '.*?'         // ANYTHING OR NOTHING
	. ')'           // END GROUP PATTERN
	. '('           // GROUP PATTERN 2
	. ':{1}'        // A COLON (EXACTLY ONE)
	. ')'           // END GROUP PATTERN
	. '#'           // REGEX DELIMITER
	;
	// INSERT THE UNDERSCORE INTO THE TAG NAME
	$rep
	= '$1'          // BACKREFERENCE TO GROUP 1
	. '_'           // LITERAL UNDERSCORE IN PLACE OF GROUP 2
	;
	// PERFORM THE REPLACEMENT
	return preg_replace($rgx, $rep, $xml);
}

// MAKE AN OBJECT
$obj = SimpleXML_Load_String(mungXML($xml));
var_dump($obj);

Open in new window

0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 38332359
This seems better: http://www.laprbass.com/RAY_temp_mavmanau.php

<?php // RAY_temp_mavmanau.php
error_reporting(E_ALL);
echo '<pre>';

// XML TEST DATA FROM THE POST AT EE
$xml = <<<XML
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
  <GetPaymentsResponse xmlns="https://px.ezidebit.com.au/">
    <GetPaymentsResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
      <Data>
        <Payment>
          <BankFailedReason/>
          <BankReceiptID>362021</BankReceiptID>
          <BankReturnCode>O</BankReturnCode>
          <CustomerName>JG testing</CustomerName>
          <DebitDate>2012-08-24T00:00:00</DebitDate>
          <CustomerID/>
          <InvoiceID>0</InvoiceID>
          <PaymentAmount>100</PaymentAmount>
          <PaymentID>WEB51409</PaymentID>
          <PaymentMethod>CR</PaymentMethod>
          <PaymentReference>JG123</PaymentReference>
          <PaymentSource>WEB</PaymentSource>
          <PaymentStatus>P</PaymentStatus>
          <ScheduledAmount>97.42</ScheduledAmount>
          <SettlementDate i:nil="true"/>
          <TransactionFeeClient>0</TransactionFeeClient>
          <TransactionFeeCustomer>2.58</TransactionFeeCustomer>
          <TransactionTime>2012-08-25T10:38:00</TransactionTime>
          <YourGeneralReference/>
          <YourSystemReference/>
        </Payment>
      </Data>
      <Error>0</Error>
      <ErrorMessage i:nil="true"/>
    </GetPaymentsResult>
  </GetPaymentsResponse>
  </s:Body>
</s:Envelope>
XML;

// FUNCTION TO MUNG THE XML
function mungXML($xml)
{
    // A REGULAR EXPRESSION TO MUNG THE XML
	$rgx
	= '#'           // REGEX DELIMITER
	. '('           // GROUP PATTERN 1
	. '\<'          // LOCATE A LEFT WICKET
	. '/{0,1}'      // MAYBE FOLLOWED BY A SLASH
	. '.*?'         // ANYTHING OR NOTHING
	. ')'           // END GROUP PATTERN
	. '('           // GROUP PATTERN 2
	. ':{1}'        // A COLON (EXACTLY ONE)
	. ')'           // END GROUP PATTERN
	. '#'           // REGEX DELIMITER
	;
	// INSERT THE UNDERSCORE INTO THE TAG NAME
	$rep
	= '$1'          // BACKREFERENCE TO GROUP 1
	. '_'           // LITERAL UNDERSCORE IN PLACE OF GROUP 2
	;
	// PERFORM THE REPLACEMENT
	$xml = preg_replace($rgx, $rep, $xml);

	// FIX THE URLS
	$xml = str_replace('https_//', 'https://', $xml);
	return $xml;
}

// TRANSFORM THE XML
$new = mungxml($xml);
echo htmlentities($new);

// MAKE AN OBJECT
$obj = SimpleXML_Load_String($new);
var_dump($obj);

Open in new window

Best regards, ~Ray
0
 

Author Closing Comment

by:mavmanau
ID: 38332425
many thanks for your assistance!! So quick as well!!
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38332442
Glad to help -- thanks for the points, ~Ray
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
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 …
Suggested Courses

577 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