xsi:nil="true" to NULL eleme...

Help
mordrukk
2011-02-12
2013-06-12
  • mordrukk
    mordrukk
    2011-02-12

    I'm using nusoap to communicate with a web service in PHP, and for a few particular parameters I need to pass the attribute:

    xsi:nil="true"

    when the element is NULL.

    I've been searching around for hours and can't seem to find any example on how to add this, or any attribute at all to node elements. 

    Creating a parameter array is very straight forward, but does anyone have a simple example of how to tack on an attribute to a given parameter element?  Thanks!

     
  • Scott Nichol
    Scott Nichol
    2011-02-12

    This is a part of XML Schema that NuSOAP does not fully implement.  Currently, if you provide a PHP NULL value for a parameter (or array element of a parameter), NuSOAP will serialize the xsi:nil="true" attribute when calling an rpc/encoded service.  When calling rpc/literal or document/literal, it simply creates an empty element.  To properly support XML Schema, NuSOAP should look for minOccurs and nillable attributes for the element to determine how to serialize NULL values.

    If I get a chance, I will look into coding this better.

     
  • mordrukk
    mordrukk
    2011-02-14

    Could you provide a syntaxual example of how to call an encoded service?  When looking at the nusoap class, I see call() defined as:

    function call($operation,$params=array(),$namespace='http://tempuri.org',$soapAction='',$headers=false,$rpcParams=null,$style='rpc',$use='encoded')

    but when I tried to invoke 'encoded' as the value of the last parameter, I don't see xsi:nil being appended.  my use:

    $result = $client->call('myCall',$myTest, NULL, NULL, NULL, NULL, NULL, 'encoded');

    What am I missing?

     
  • Scott Nichol
    Scott Nichol
    2011-02-14

    If you are using WSDL, which hopefully you are, only the first two parameters to call are used.  The rest are taken from the WSDL.  If the service is implemented as document/literal, you can never use 'encoded' to generate a valid request.

    I am going to look at the XML Schema spec and NuSOAP code right now to see how difficult it is to make NuSOAP behave correctly (or at least more correctly) in this regard.

     
    • Msibbald
      Msibbald
      2013-06-12

      Hi Scott,

      I'm also trying to get this working, but got the latest version (I think). I'm not seeing xsi:nil="true" in my request.

      Could you get me an example?

      Thanks

       
      Last edit: Msibbald 2013-06-12
  • Scott Nichol
    Scott Nichol
    2011-02-14

    OK, I made some changes to the wsdl class and checked them into CVS (both class.wsdl.php and nusoap.php).  The changes do not break anything I tested.  They *may* allow you to get your nillable value serialized correctly.  Let me know how it works for you.

     
  • mordrukk
    mordrukk
    2011-02-14

    Brilliant!  As soon as I copied over the new classes, my result worked, and I can clearly see the xsi:nil attribute appended properly when debugging.

    Thank you!!

     
  • Raúl Gómez
    Raúl Gómez
    2012-08-24

    Hi Snichol, I have the same problem and I see that you've solved, where I can find the changes you have done to solve the problem?

    thanks

     
  • Raúl Gómez
    Raúl Gómez
    2012-08-24

    sorry, I ask the question differently. as I have to make the call to encode the nillables values?.