I am trying to write a web service API using PHP and the Yii framework. This means that I will be using SOAP web services, since Yii does not directly support RESTful web services.
I would like to return results in XML format, as strings (this might be stupid, but I'm working with rather cumbersome data types that would make life more difficult for the web service clients trying to use them). The problem I'm facing is that the XML I'm returning contains tags, which leads to the strings not being read properly by the web service client.
For instance, I can return this string in one of my web services:
"hello
"
But not this string:
"<hello>
"
(An empty string is r开发者_C百科ead by the client)
So, is there a way for a SOAP web service to return an XML document as a string (in general, or using Yii in particular)?
This should really be done by the framework (don't know about Yii though), but since it doesn't seem to work automatically for you, try escaping the data first:
$data_to_send = htmlspecialchars($data_to_send);
If Yii doesn't encode the data, your client will see the correct output (the raw XML string) when fetching the data from their SOAP library. If Yii, however, does encode the data, it will get double-encoded which is probably not what you want, but if it does encode it you shouldn't have this problem in the first place...
If your data contains characters that are also XML tags, you can use the CDATA option.
<value><![CDATA[<hello>]]></value>
Please don't use soap. It is one if the worst technologies ever made (see the numerous posts on SO) . Yii does support REST now (fully as of 1.17). Just use JSON format. Do you need to delete or insert from the client?
精彩评论