7

I have found numerous explanations about how SoapClient expects you to set attributes in a request, but I simply cannot find a way to read attributes from a response.

For example, my SoapClient response has these elements in it:

...
<ns:index>
   <ns:uid expdate="2013-09-03 14:30:00">JOWtest002</ns:uid>
   <ns:uid expdate="2013-02-07 15:00:00">JOWtest003</ns:uid>
</ns:index>
...

However, the "expdate" attribute is never attached to the "index" stdClass

["index"]=>
  object(stdClass)#80 (1) {
  ["uid"]=>
    array(2) {
    [0]=>
      string(10) "JOWtest002"
    [1]=>
      string(10) "JOWtest003"
    }
}

I have tried using a SoapClient classmap to bind this to an object, but unfortunately, the WSDL does not define the "uid" element as a complexType, so it does not map the attributes either. Binding "index" itself to a class doesn't work.

Any suggestions? I really want to avoid parsing the XML by giving it to SimpleXML or DOMDocument.

Jesse Skrivseth
  • 481
  • 2
  • 13
  • Would using namespace help you? http://stackoverflow.com/q/8525020/1513471 – believe me Mar 15 '13 at 16:37
  • Thank you. Can you clarify on why namespace would be an issue? The WSDL defines the usual SOAP wrapping namespaces and we do use a different namespace than declared in my example here. – Jesse Skrivseth Mar 15 '13 at 17:28
  • Because namespace pointing to the xml attributes that's why I suggest namespace. – believe me Mar 17 '13 at 15:33
  • I found no working solution to this. Unfortunately I was forced to parse the XML, from SoapClient's getLastResponse() method, into a DOMDocument and then manually select out the attributes and put them into a map that matches the stdClass object that SoapClient produces. It's hacky, but it works. I honestly cannot believe that SoapClient does not natively support mapping XML attributes to the objects and that it's seemingly a non-issue for most developers in the wild. – Jesse Skrivseth Mar 22 '13 at 14:24
  • I have exactly the same issue as you. I'm using an external API, which we obviously can't change and it ONLY returns object properties as node attributes. I've literally spent a week trying to get it to work but it looks like I'll have to go down the custom DOMDocument route too. Not just for parsing but also for generating requests as the API expects e.g. search parameters as attributes and SOAP client only does nodes. Ridiculous if you ask me... – Andris Aug 12 '13 at 10:19

1 Answers1

0

I work quite a bit with XML and it is a real chore. In my experience, and if your open to use a library that has written an excellent wrapper around handling a SOAP response would be to implement Sabre's XML library found at this link.

It is really easy to send and read responses. The documentation is really good and they have a lot of examples on their site that will help you in using the library effectively.

TesterT
  • 11
  • 2
  • Just a helpful library that has quite a bit of power and extensibility that I am in no way affiliated to. If you would like to use PHP's SOAP client and re-build another library around that then be my guest. I use it allot so just thought I would suggest it. – TesterT Aug 28 '17 at 14:12
  • 1
    Ok fair enough. Will try make it not sound "leaflet like" in the future, thanks for feedback – TesterT Aug 28 '17 at 14:19