Im in the process of connecting to a SOAP api, passing some data and then reading the response. Im to the point where I get the SOAP request to send and I get a response but I cannot seem to figure out how to parse the returned XML.
First I pass credentials to receive an auth_ticket:
$rap_soapUrl = "https://technet.rapaport.com/webservices/prices/rapaportprices.asmx?wsdl";
$client = new \SoapClient($rap_soapUrl, array('trace' => 1));
$result = $client->Login($rap_credentials);
$response = $client->__getLastResponse();
This is the point where Im getting stuck. If I echo $response I get
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Header><AuthenticationTicketHeader xmlns="http://technet.rapaport.com/"><Ticket>TICKETHASH</Ticket></AuthenticationTicketHeader></soap:Header><soap:Body><LoginResponse xmlns="http://technet.rapaport.com/" /></soap:Body></soap:Envelope>
What I need to parse out is TICKETHASH, which is then used in the next request.
I am able to manually parse the string, searching for anything between <Ticket>
and </Ticket>
but it feels very hacky and not the correct way to handle it.
I tried to use $xml = simplexml_load_string($response);
but it returns an empty simplexml object.