Jump to content

Parsing a SOAP Response


iPixel

Recommended Posts

Ok this is driving me NUTS!

 

After using SoapClient() this is the response i get back...

 

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <soap:Body>
    
        <ns1:GetRegistrationURLResponse xmlns:ns1="http://impl.service.tempuri.com">
        
            <ns1:out>
            
                <errorCode xmlns="http://model.tempuri.com">0</errorCode>
                
                <errorMessage xmlns="http://model.tempuri.com" xsi:nil="true" />
                
                <registrationURL xmlns="http://model.tempuri.com">
                    https://www.tempuri.com/external/authenticate?org=orgname&token=uXiqcPV4%2FuEifbaR80PVBTxH4Oqd3tF%2BiEYaz%2F1OHJG7b5oxN7Bi8AIulmtbwATnjri2P1vCNy%2Fu77OzQEV2lQ%3D%3D
                </registrationURL>
                
            </ns1:out>
                
        </ns1:GetRegistrationURLResponse>
        
    </soap:Body>

</soap:Envelope>

 

So all i really need to pull out of there is the <registrationURL>

 

I assign the response to a variable

<?php 
$xml_response = $client->__getLastResponse(); 
?>

 

use SimpleXML

<?php 
$xml = simplexml_load_string($xml_response,NULL,NULL,"http://schemas.xmlsoap.org/soap/envelope/"); 
?>

 

Using the code

print_r($xml);

 

displays this --> SimpleXMLElement Object ( [body] => SimpleXMLElement Object ( ) )

 

 

I have tried many ways, what i have now is this:

<?php
$xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
$xml->registerXPathNamespace('ns1', 'http://impl.service.tempuri.com');
#$xml->registerXPathNamespace('registrationURL', 'http://model.tempuri.com');


foreach ($xml->xpath('//ns1:GetRegistrationURLResponse/ns1:out') as $item)    
{ 
   echo $item->asXML();    
}
?>

 

but the result of that is

 

0https://www.tempuri.com/external/authenticate?org=nyit&token=uXiqcPV4%2FuEifbaR80PVBTxH4Oqd3tF%2BiEYaz%2F1OHJG7b5oxN7Bi8AIulmtbwATn3QmJanSYWqzS%2FgZM4eR%2Fcg%3D%3D

 

parsed by browser... actual source XML is

 

<ns1:out><errorCode xmlns="http://model.tempuri.com">0</errorCode><errorMessage xmlns="http://model.tempuri.com" xsi:nil="true"/><registrationURL xmlns="http://model.tempuri.com">https://www.tempuri.com/external/authenticate?org=orgname&token=uXiqcPV4%2FuEifbaR80PVBTxH4Oqd3tF%2BiEYaz%2F1OHJG7b5oxN7Bi8AIulmtbwATn3QmJanSYWqzS%2FgZM4eR%2Fcg%3D%3D</registrationURL></ns1:out>

 

but i cannot for the life of me just pull out registrationURL so that i can somehow turn it into a link.

 

Any ideas?

Link to comment
Share on other sites

Your print_r tell you how it's done! :D

 

$xml = simplexml_load_string($resp,NULL,NULL,"http://schemas.xmlsoap.org/soap/envelope/");

$xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
$xml->registerXPathNamespace('ns1', 'http://impl.service.tempuri.com');

$xml_resp = $xml->xpath('//ns1:GetRegistrationURLResponse/ns1:out');

echo $xml_resp[0]->registrationURL;

 

I'm not good with XPath or namespaces, so I can't provide you with the XPath query to get the result.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.