Jump to content


Photo

Encoding array with PHP-SOAP


  • Please log in to reply
2 replies to this topic

#1 jonathankart

jonathankart
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 03 August 2006 - 07:56 PM

Hi,

I'm trying to use the PHP 5 SOAP extension and am having trouble encoding outgoing requests with arrays.

The relevent portion of the schema looks like this:
<complexType name="SessionData">
<sequence>
              <element maxOccurs="unbounded" minOccurs="0" name="kvPair" type="tns:KVPair"/>
        </sequence>
</complexType>

We are using a simple object to encoded the sequnce of kvPairs:

class SessionData{
  var $kvPair = array(new KVPair('first_name', 'Jason'),new KVPair('last_name', 'Bourne'));
}

When we sendthe request, the xml comes out like this:
<SessionData>
    <kvPair>
    <item>
                <key>first_name</key>
                <value>Jason</value>
            </item>
    <item>
                <key>last_name</key>
                <value>Bourne</value>
            </item>
    </kvPair>
</SessionData>
this doesn't match the schema.  We need a way to generate just a sequence of kvPairs like the schema says:
<SessionData>
<kvPair>
            <key>first_name</key>
            <value>Jason</value>
        </kvPair>
<kvPair>
            <key>last_name</key>
            <value>Bourne</value>
        </kvPair>
</SessionData>


How can we do this?  Our only thought is to subclass the SoapClient and apply an  xsl transform on the request before it goes out, but this doesn't seem scalable to me.  Any ideas are much appreciated.

Thanks!

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 04 August 2006 - 01:44 AM

what does the class KVPair do?  What is the code for it?  If you don't want to, or can't, post the code for it, then try not using it when building the array and see if you get the same error:

class SessionData{
   var $kvPair = array('first_name' => 'Jason','last_name' => 'Bourne');
}


#3 jonathankart

jonathankart
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 04 August 2006 - 11:50 PM

It's just a struct basically.

class KVPair
{
  var $key;
  var $value;
 
  function __construct($key,$value)
  {
      $this->key = $key;
      $this->value = $value;
  }

}




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users