5

I'm using PHP SoapServer class and try to put plain XML inside the body of the SOAP response.

Case 1:

My WSDL has

<element name="getDataResponse" type="xsd:string"/>

I encode the response

return new SoapVar($my_xml,XSD_ANYXML)

PHP SoapClient says

SOAP-ERROR: Encoding: Violation of encoding rules

Case 2:

WSDL

<element name="getDataResponse" type="xsd:string"/>

response encoding

return new SoapVar($my_xml,XSD_STRING)

response XML has all < encoded as &lt; and > as &gt;

Case 3:

WDSL

<element name="getDataResponse">
  <complexType>
   ... 
  </complexType>
</element>

where complexType corresponds the structure of XML to return

response encoding

return new SoapVar($my_xml,XSD_ANYXML)

now return type is an object, not XML string

Case 4

same as case 3 except encoding as SOAP_ENC_OBJECT. Again result will be object.

Please help! How can I get just plain XML text as body of the SOAP response?

tok
  • 909
  • 1
  • 10
  • 21
  • You could try to recursively apply `new SoapVar()` on your actual data structure instead of writing the XML in a string. – Ja͢ck Mar 15 '13 at 10:29
  • 1
    Yes, but the question was that **if I want to write out XML as a string**, how can I do it. – tok Mar 15 '13 at 11:13

1 Answers1

5

Have you tried this?

return new SoapVar(
     '<ns1:xmlDocument>'.$my_xml.'</ns1:xmlDocument>',
     XSD_ANYXML
);

There are other solutions as well at this PHP page. (See 'User Contributed Notes' section)

Zanshin13
  • 980
  • 4
  • 19
  • 39
Jodes
  • 14,118
  • 26
  • 97
  • 156
  • This will return NULL since the name of the return message in WSDL is not xmlDocument. `$xmlvar = new SoapVar(''.$xmlDocument.'',XSD_ANYXML);` will lead to case 1. – tok Mar 15 '13 at 11:07