Link to home
Create AccountLog in
Avatar of Nika Gudge
Nika GudgeFlag for United States of America

asked on

how to convert a soap response to an actual xml document

this is my soap response $result:

<?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>
<GetDataResponse xmlns="http://.../.../...">
<GetDataResult>
<LoanID>348</LoanID>
<LastName>PWKZFX</LastName>
<PhoneHome>619-555-1212</PhoneHome>
</GetDataResult>
</GetDataResponse>
</soap:Body>
</soap:Envelope>

my code:
        header('Content-type: application/xml');
        var_dump($result);
        $xml = simplexml_load_string($result);
        $sxe = new SimpleXMLElement($xml);

        $sxe->registerXPathNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope");
        $tk = $sxe->xpath('soapenv:GetDataResult');

        foreach($tk as $token){
        echo $token . "\n";
        }
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

I'm not sure what the problem is or what you're asking. The SOAP content -is- an XML document, but based on your code, I assume you mean you want to convert the SOAP content to a SimpleXML object. However, you already have the correct code for converting it to a SOAP object, so I'm not sure what is left...
Avatar of Nika Gudge

ASKER

the above code does not work. it does not return me any result. I'm trying to access the value of elements LoanID, LastName
What is the value of the namespace here?
<GetDataResponse xmlns="http://.../.../...">
ASKER CERTIFIED SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account