1

I had used curl to call the soap server and i got the response like this:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <GenerateAuthPasswordResponse xmlns="NepalTelecom.AuthGateway">
            <GenerateAuthPasswordResult>abcd-efgh</GenerateAuthPasswordResult>
            <ResultCode>1</ResultCode>
        </GenerateAuthPasswordResponse>
    </soap:Body>
</soap:Envelope>

and when i tried to parse the soap xml as:

$response = $this->SoapModel->soapCall($xml , $this->vas_wsdl_url);
 $obj = simplexml_load_string($response);
 echo $obj;die();

[Note: where $response is the above soap response provided in soap xml]

and i get the $obj as some error like this:

Severity: Warning
Message:  simplexml_load_string(): namespace warning : xmlns: URI NepalTelecom.AuthGateway is not absolute

please any body could help so fix this issue. Thank you in advance.

Javed Ali
  • 43
  • 1
  • 8
  • Refer this link. this may helpfull to you. https://stackoverflow.com/questions/4194489/how-to-parse-soap-xml – Alex Nov 30 '17 at 11:35
  • I had already tried that but could not get the required response. Please if you can then provide the response in array for the soap xml which i have provided above. – Javed Ali Nov 30 '17 at 11:54

1 Answers1

0

Try this.

<?php

$xml = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <GenerateAuthPasswordResponse >
            <GenerateAuthPasswordResult>abcd-efgh</GenerateAuthPasswordResult>
            <ResultCode>1</ResultCode>
        </GenerateAuthPasswordResponse>
        <GenerateAuthPasswordResponse >
            <GenerateAuthPasswordResult>abcd-efgh</GenerateAuthPasswordResult>
            <ResultCode>1</ResultCode>
        </GenerateAuthPasswordResponse>
    </soap:Body>
</soap:Envelope>';

$xml = simplexml_load_string($xml, NULL, NULL, "http://schemas.xmlsoap.org/soap/envelope/");
$ns = $xml->getNamespaces(true);
$soap = $xml->children($ns['soap']);
$res = $soap->Body->children();

print_r($res);
Alex
  • 112
  • 1
  • Thank you Alex for responding my question to help me. I appreciate it. But sorry to say that i still didn' t get the what i required. i Wanted to extract the values between the tags. I tried the way you provided though i had already tried that way innitailly. Sorry to say it does'nt work. The error is: simplexml_load_string(): namespace warning : xmlns: URI NepalTelecom.AuthGateway is not absolute – Javed Ali Dec 01 '17 at 08:31
  • I had run this program, but did not get any error. Answer I got: SimpleXMLElement Object ( [GenerateAuthPasswordResponse] => Array ( [0] => SimpleXMLElement Object ( [GenerateAuthPasswordResult] => abcd-efgh [ResultCode] => 1 ) [1] => SimpleXMLElement Object ( [GenerateAuthPasswordResult] => abcd-efgh [ResultCode] => 1 ) ) ) – Alex Dec 01 '17 at 09:38
  • Ok. May be there must be some authentication error. Any ways i had used strip_tags to get the content of the specific tag as i required. Thank you alex. I got my answer. You helped me a lot and gave me lots of ideas. – Javed Ali Dec 01 '17 at 09:42