0

xml content sounds successful but I can't get the information I want from the content

Post Xml

$xml = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsc="http://ws.ups.com/wsByTrackingNumber">
                      <soapenv:Body>
                        <GetTransactionsByTrackingNumber_V1 xmlns="http://ws.ups.com/wsByTrackingNumber/">
                          <SessionID>'.strip_tags($response2).'</SessionID>
                          <InformationLevel>1</InformationLevel>
                          <TrackingNumber>XXXXXX996800071633</TrackingNumber>
                        </GetTransactionsByTrackingNumber_V1>                   
                      </soapenv:Body>
                    </soapenv:Envelope>';

I return the result successfully by submitting my information. But I can't get the xml tags as I want.

Response Xml

<?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:Body>
        <GetTransactionsByTrackingNumber_V1Response xmlns="http://ws.ups.com.tr/wsPaketIslemSorgulamaEng/">
            <GetTransactionsByTrackingNumber_V1Result>
                <PackageTransaction>
                    <TrackingNumber>XXXXX996800071633</TrackingNumber>
                    <ProcessTimeStamp>20191204-181757</ProcessTimeStamp>
                    <OperationBranchName>CITY HUB</OperationBranchName>
                    <StatusCode>31</StatusCode>
                    <ExceptionCode>--</ExceptionCode>
                    <ProcessDescription1>PICKED UP PER CUSTOMER CALL</ProcessDescription1>
                    <ProcessDescription2 />
                    <RecordId>3838837092</RecordId>
                    <InformationLevel>1</InformationLevel>
                    <ErrorCode>0</ErrorCode>
                    <ErrorDefinition />
                </PackageTransaction>
                <PackageTransaction>
                    <TrackingNumber>XXXXX996800071633  </TrackingNumber>
                    <ProcessTimeStamp>20191204-210346</ProcessTimeStamp>
                    <OperationBranchName>CITY HUB</OperationBranchName>
                    <StatusCode>12</StatusCode>
                    <ExceptionCode>--</ExceptionCode>
                    <ProcessDescription1>SCAN INTO A CONTAINER</ProcessDescription1>
                    <ProcessDescription2>B89160315Z7</ProcessDescription2>
                    <RecordId>3838985579</RecordId>
                    <InformationLevel>1</InformationLevel>
                    <ErrorCode>0</ErrorCode>
                    <ErrorDefinition />
                </PackageTransaction>
            </GetTransactionsByTrackingNumber_V1Result>
        </GetTransactionsByTrackingNumber_V1Response>
    </soap:Body>
</soap:Envelope>

Curl Xml Post

$url = "http://ws.ups.com/QueryPackageInfo/wsQueryPackagesInfo.asmx?op=GetTransactionsByTrackingNumber_V1";
        //Initiate cURL
        $curl = curl_init($url);
        curl_setopt ($curl, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        $result = curl_exec($curl);
        $info = curl_getinfo($curl);
        if(curl_errno($curl)){
            $data['curlhata'] = curl_error($curl); 
        }
        $xml = simplexml_load_string($result);
        print_r($xml);


        foreach($xml  as $xmls){
            print_r($xmls);
        }

I need to return PackageTransaction tags, but I can't make it

Mahlika
  • 29
  • 8
  • 2
    Does this answer your question? [How to parse SOAP XML?](https://stackoverflow.com/questions/4194489/how-to-parse-soap-xml) – krylov123 Dec 05 '19 at 10:33
  • 1
    Your problem is in SOAP. Take a peek here https://stackoverflow.com/questions/4194489/how-to-parse-soap-xml – krylov123 Dec 05 '19 at 10:34
  • yes as it worked but I still do not get the tags. `$your_xml_response = 'PackageTransaction'; $clean_xml = str_ireplace(['SOAP-ENV:', 'SOAP:'], '', $result); $xmls = simplexml_load_string($clean_xml); foreach($xmls as $rexml){ //echo $rexml['TrackingNumber']; print_r($rexml);` } – Mahlika Dec 05 '19 at 11:37
  • You should be using PHP's built-in SoapClient class for this. Otherwise it's simply XML parsing, which is also easy enough. – miken32 Dec 05 '19 at 23:34

0 Answers0