How to solve this read XML response using PHP


Ask A Question





Login To post a question

I am creating a web site. In this web site I use a SOAP request to get a response. First of all I I used cURL to send the request and I got the response. But , when I tried to print_r XML response, it gives me this –

SimpleXMLElement Object ( )

Basically what I want to do is, I want to read these XML line by line as I want. Lets say I want to get ConversionId.

So, how can I do this ??

Here is the function I used to send the SOAP request.

public function authticate(){

$url = 'https://webservices.havail.sabre.com';
        $tokengenheaders = array(
            'Content-Type: text/xml'
        );

        $AuthData = '<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:eb="http://www.ebxml.org/namespaces/messageHeader" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
   <soap-env:Header>
      <eb:MessageHeader soap-env:mustUnderstand="1" eb:version="1.0">
         <eb:From>
            <eb:PartyId />
         </eb:From>
         <eb:To>
            <eb:PartyId />
         </eb:To>
         <eb:CPAId>ID45</eb:CPAId>
         <eb:ConversationId>IdOfConversion</eb:ConversationId>
         <eb:Service>SessionCreate</eb:Service>
         <eb:Action>SessionCreate</eb:Action>
         <eb:MessageData>
            <eb:MessageId>MsgId</eb:MessageId>
            <eb:Timestamp>2017-11-27T09:58:31Z</eb:Timestamp>
         </eb:MessageData>
      </eb:MessageHeader>
      <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/12/utility">
         <wsse:UsernameToken>
            <wsse:Username>Kist</wsse:Username>
            <wsse:Password>Kistlak</wsse:Password>
            <Organization>FSG</Organization>
            <Domain>SN</Domain>
         </wsse:UsernameToken>
      </wsse:Security>
   </soap-env:Header>
   <soap-env:Body>
      <eb:Manifest soap-env:mustUnderstand="1" eb:version="1.0">
         <eb:Reference xlink:href="cid:rootelement" xlink:type="simple" />
      </eb:Manifest>
      <SessionCreateRQ>
         <POS>
            <Source PseudoCityCode="5H7D" />
         </POS>
      </SessionCreateRQ>
      <ns:SessionCreateRQ xmlns:ns="http://www.opentravel.org/OTA/2002/11" />
   </soap-env:Body>
</soap-env:Envelope>';

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://webservices.sabre.com");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $AuthData); // the SOAP request
        curl_setopt($ch, CURLOPT_HTTPHEADER, $tokengenheaders);
        curl_setopt($ch, CURLOPT_VERBOSE, false);
        $soaptoken = curl_exec($ch);
        curl_close($ch);

        //$xmlElement = new SimpleXMLElement($soaptoken, LIBXML_NOCDATA);

        $xml = simplexml_load_string($soaptoken);
        print_r ($xml) ; die();

        return $soaptoken;

    }

Here is the XML response.

<?xml version="1.0" encoding="UTF-8"?>
<soap-env:Envelope
    xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
    <soap-env:Header>
        <eb:MessageHeader
            xmlns:eb="http://www.ebxml.org/namespaces/messageHeader" eb:version="1.0" soap-env:mustUnderstand="1">
            <eb:From>
                <eb:PartyId eb:type="URI"/>
            </eb:From>
            <eb:To>
                <eb:PartyId eb:type="URI"/>
            </eb:To>
            <eb:CPAId>Id234</eb:CPAId>
            <eb:ConversationId>ConversionId</eb:ConversationId>
            <eb:Service eb:type="sabreXML">Session</eb:Service>
            <eb:Action>SessionCreateRS</eb:Action>
            <eb:MessageData>
                <eb:MessageId>MsgId</eb:MessageId>
                <eb:Timestamp>2019-03-11T09:27:32</eb:Timestamp>
                <eb:RefToMessageId>MsgRef</eb:RefToMessageId>
            </eb:MessageData>
        </eb:MessageHeader>
        <wsse:Security
            xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext">
            <wsse:BinarySecurityToken valueType="String" EncodingType="wsse:Base64Binary">SecToken</wsse:BinarySecurityToken>
        </wsse:Security>
    </soap-env:Header>
    <soap-env:Body>
        <SessionCreateRS
            xmlns="http://www.opentravel.org/OTA/2002/11" version="1" status="Approved">t
            <ConversationId>ConversionId</ConversationId>
        </SessionCreateRS>
    </soap-env:Body>
</soap-env:Envelope>

For more info please click herehttps://stackoverflow.com/q/55115749



Have a question or need a custom quote?
info@smartinfocare.com