1

I have a response in the following format

<?xml version='1.0'?>
<SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns='urn:xtk:myQyery' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
<SOAP-ENV:Body>
    <ExecuteQueryResponse xmlns='urn:xtk:myQyery' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
        <pOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
            <recipient email="[email protected]"/>
        </pOutput>
    </ExecuteQueryResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

So first thing I do is load the string

public function checkResponse($serverResponse) {
    $xml = simplexml_load_string($serverResponse);

    if($xml->children('SOAP-ENV', true)->Body->Fault) {
        return false;
    }
    else {
        return true;
    }
}

The first thing I do is look for a fault, and if there is one, return false. If everything is ok, I need to return the email address from the xml. I have tried the following without success

return $xml->children('SOAP-ENV', true)->Body->ExecuteQueryResponse->pOutput->recipient;

How would I go about getting the email address?

Thanks

1 Answer 1

1

email is an attribute of the 'recipient' node.

You can try this:

return $xml->children('SOAP-ENV', true)->Body->ExecuteQueryResponse->pOutput->recipient->attributes()->email

http://php.net/simplexmlelement.attributes

Sign up to request clarification or add additional context in comments.

2 Comments

If I do that I get both Trying to get property of non-object and Call to a member function attributes() on a non-object
Oh, yes, sorry. That's because de namescpaces. Try this: $xml->children('SOAP-ENV', true)->Body->children()->ExecuteQueryResponse->pOutput->recipient->attributes()->email sitepoint.com/simplexml-and-namespaces

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.