Jump to content

Parse SOAP Response


AeroProDrive

Recommended Posts

Hi Guys,

I have this SOAP message to be parsed using SimpleXML:

<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>
    <isokresponse xmlns="http://tempuri.org/">
      <isokresult>1</isokresult>
    </isokresponse>
  </soap:body>
</soap:envelope>

Then I load the XML:

$xml = simplexml_load_string($result);

I assume I need to register namespace e.g.

$xml->registerXPathNamespace("soap","http://schemas.xmlsoap.org/soap/envelope/");

But what's next? How do I get the value of the element isokresult?

Thank you so much

Link to comment
Share on other sites

If all you want is the isokresult then you can get it... well, I won't say "easily" because SOAP just loves using namespaces, but it is a one-liner. Kinda. Don't need XPath.

(string)$xml
	->children("http://schemas.xmlsoap.org/soap/envelope/") // switch to soap namespace
	->body // <soap:body>
	->children("http://tempuri.org/") // switch to this isokwhatever namespace
	->isokresponse // <isokresponse>
	->isokresult // <isokresult> (still in the isok namespace)

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.