Jump to content

Encoding array with PHP-SOAP


jonathankart

Recommended Posts

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!
Link to comment
Share on other sites

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:

[code]class SessionData{
  var $kvPair = array('first_name' => 'Jason','last_name' => 'Bourne');
}[/code]
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.