Monday, 9 September 2013

PHP SoapClient with multiple copies of the same tag

PHP SoapClient with multiple copies of the same tag

I am writing a PHP SoapClient script to query a SOAP server and return the
response. I am able to submit to the server correctly using the WSDL, but
now I need to have a way to submit with multiple instances of the same tag
(in this case attribute) each with a different value for a specific
parameter.
Currently, I submit the parameters to the SoapClient with an array. The
section I am working on is:
"attributes" => array(
"attribute" => array("name" => "Profession") );
Which generates the XML:
<ns1:attributes>
<ns1:attribute name="Profession"/>
</ns1:attributes>
But what I am after is this:
<ns1:attributes>
<ns1:attribute name="Profession"/>
<ns1:attribute name="Email"/>
</ns1:attributes>
And so on, having multiple tags with different values for the 'name' field.
I know I can't use a regular array, and I've tried to work out how to use
SoapVar, but the farthest I've gotten is to create multiple copies of the
tag, but the 'data' field for the SoapVar goes in as the value of the tag:
<attribute>VALUE_1</attribute>
<attribute>VALUE_2</attribute>
I can't find a way to add differing values to a parameter field (name) for
the tags.

No comments:

Post a Comment