I have to call a SOAP web service using a SoapClient object. One of the parameters has to contain some XML included in a CDATA section, like this:
<ns2:productInformation><![CDATA[<foo><bar>baz</bar></foo>]]></ns2:productInformation>
Note the node namespace, it's the source of my pain...
If I create a string SoapVar
, the XML is encoded...
new SoapVar('<![CDATA[<foo><bar>baz</bar></foo>]]>', XSD_STRING, null, null, 'productInformation', self::MY_NAMESPACE)
<ns2:productInformation xsi:type="xsd:string"><![CDATA[<foo&t;<bar>baz</bar></foo>]]></ns2:productInformation>
So I can't do this way. The only alternative I've found is to use the XSD_ANYXML
encoding, like this:
new SoapVar('<ns2:productInformation><![CDATA[<foo><bar>baz</bar></foo>]]></ns2:productInformation>', XSD_ANYXML)
It works, but it's bad... Look at the hard coded namespace shortcut ("ns2").
So do you have an idea to create a CDATA section containing XML?
I've had the same requirement (maldesigned vendor web service that requires embedding of part of the request as XML encoded in a string, and which blows up if you give it an entity-encoded string instead of CDATA).
To the best of my ability to determine, your SoapVar
workaround is as good as it gets. Sorry. I'm pretty unhappy about having to hardcode a namespace reference myself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With