need to take SOAP headers out of a simplexml object
Posted: Mon Mar 29, 2010 11:31 am
Hi Guys,
I have been arguing with my computer all day. It just doesn't want to do as it's told!
essentially I have been able to build an xml file in the format that I want using simplexml and stick it in a soap header, send it to a server in a post array and get a response. This is a huge victory for me
It is basically sending info of a motor insurance risk and getting a response of quote ref, premium, terms etc.
I know this looks strange but I needed a soap envelope on the request so I took the <?xml version="1.0" encoding="UTF-8" ?> off of the results of the simplexml so that I could stick a soap header in between that and the xml data.
I'm then using CURL to bring the xml response into a variable:
Then I'm loading the results into a simpleXMLElement and attempting to display the quoted premium:
This doesn't seem to work. It just returns blank. If I look at the $QResponse->asXML; I can see that the GrossPremium element is populated so I can only assume that the issue is to do with the SOAP header that is being returned. Is there any way of removing the SOAP header without searching the curled string for <root element> and </root element> and substringing everything in between?
I tried using PHP SOAP earlier but the WS im trying to connect to doesn't like the way the xml is formatted by the soapClient object.
Thanks for reading,
Ben
I have been arguing with my computer all day. It just doesn't want to do as it's told!
essentially I have been able to build an xml file in the format that I want using simplexml and stick it in a soap header, send it to a server in a post array and get a response. This is a huge victory for me
Code: Select all
$xmlToSend = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n" .
'<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><SOAP-ENV:Body>' . "\n" .
substr($xml2->asXML(),22) . //XML body
'</SOAP-ENV:Body>' . "\n" .
'</SOAP-ENV:Envelope>';I'm then using CURL to bring the xml response into a variable:
Code: Select all
$ch = curl_init(SOURCE_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlToSend);
$xmlReceived = curl_exec($ch);
curl_close($ch);Code: Select all
$QResponse = new SimpleXMLElement($xmlReceived);
echo "<pre>Premium Returned:" . (string) $QResponse->GrossPremium . "\n";I tried using PHP SOAP earlier but the WS im trying to connect to doesn't like the way the xml is formatted by the soapClient object.
Thanks for reading,
Ben