bobmyles
1029
2
General

Parsing soap response in PHP

Posted 1 year ago by bobmyles

I am new in Soap Web Services. I am trying to get the values from a soap request;

        <?xml version="1.0" encoding="UTF-8"?>
           <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
           <soapenv:Body>
              <c2b:C2BPaymentValidationRequest xmlns:c2b="http://cps.huawei.com/cpsinterface/c2bpayment">
                 <TransID>3IN40005PY</TransID>
                 <TransTime>20160923143639</TransTime>
                 <TransAmount>3000</TransAmount>
                 <BusinessShortCode>10069</BusinessShortCode>
                 <MSISDN>86812530102</MSISDN>
                 <KYCInfo>
                    <KYCName>FirstName</KYCName>
                    <KYCValue>aaa</KYCValue>
                 </KYCInfo>
                 <KYCInfo>
                    <KYCName>MiddleName</KYCName>
                    <KYCValue>bbb</KYCValue>
                 </KYCInfo>
                 <KYCInfo>
                    <KYCName>LastName</KYCName>
                    <KYCValue>ccc</KYCValue>
                 </KYCInfo>
              </c2b:C2BPaymentValidationRequest>
           </soapenv:Body>
        </soapenv:Envelope>

I tried making an object

$xml=simplexml_load_string($response) or die("Error: Cannot create object");

So that I can read the values as below;

$TransID=$xml->TransID; 
$TransTime=$xml->TransTime; 
$TransAmount=$xml->TransAmount;

But it fails here die("Error: Cannot create object");

Or even better how can I change the soap request to json and get the values? Anyone?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.