PHP 5 soap request with XML-string param.

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I have a wsdl soap request structure as follows:

<soap:Envelope xmlns:xsi="..." xmlns:xsd="..." xmlns:soap="...">
<soap:Header>... </soap:Header>
<SaveItem xmlns="...">

I cant seem to work out how to add an string representation of an xml
document as the ItemXml parameter.
Currently I use the __soapCall() function with an assoc array as the
second argument as shown below:

$params = array("ItemXml" => $itemxml, "PropertyView" =>
$result = $this->soapclient->__soapCall($function,
array("parameters"=>$params), null, $this->soapheaders);

There is a valid XML string as the ItemXML param, however, using the
__getLastResponse() function I get an empty XML string as the ItemXML
param. eg.

<SOAP-ENV:Envelope xmlns:SOAP-ENV="..." xmlns:ns1="...">
<ns1:ItemXml />

Thankyou in advance for any response

Re: PHP 5 soap request with XML-string param.

If you want to pass an xml document node as a function parameter, your
need to create a SoapVar object with a text represention of the xml
node and the XSD_ANYXML encoding constant. However, this constant is
not exported by the extension and is not documented for some unknown

Therefore, to get this to work you must either register the XSD_ANYXML
#define as a PHP constant, or use the integer value of the constant
when creating the SoapVar, which is 147.

$soapvar = new SoapVar($xml_text, 147);

$params = array("ItemXml" => $soapvar, "PropertyView" => "blah");
$result = $this->soapclient->__soapCall("SaveItem",
array("parameters"=>$params), null, $this->soapheaders);

However, this still doesnt give the correct result. For some reason,
the ItemXml parameter node is not wrapped around the associated xml
parameter in the soap request, and the following soap is produced
(assumming '<item>blah</item>' is used as the $xml_text):

<SOAP-ENV:Envelope xmlns:SOAP-ENV="..." xmlns:ns1="...">

Site Timeline