Hi Matthew,
I'm trying to embed some html in a array returned from a function
that is used by Zend_Xml_Rpc_Server and having erratic results.
Sometimes it works and sometimes it doesn't but I'm not sure how to
specify the content in any way. For example in the example code I
tried things like htmlentities() or...
'<![CDATA[' . $content->body . ']]>',
...but in many cases (particularly with tricky html) the description
ends up as an empty string.
Oof. I've never tried sending HTML back in my XML-RPC responses
before.
The problem you run into, as you're noting, is that you're
wrapping the
HTML in XML, which is always problematic -- you need to use
entities, or
CDATA, and I'm not entirely sure XML-RPC will play well with CDATA
anyways.
What I am working on is the blogger and metaweblog api's to use
desktop editors for "blog" content so sending the html is really
the key. I have ...on a quick Googling... found examples of using
CDATA in xml-rpc:
http://blogger-bee.com/index.php/XML-RPC_spell_checker
Try base64-encoding the HTML. This will mean extra work on the
receiving
end, but should make it safe enough to pass embedded in the XML-RPC
(which, I believe, may have been one of the rationale's behind
having a
'base64' XML-RPC type in the first place).
I did try using the native php base64 encoding but the problem
there is that I cannot control the receiving end and within the
struct it's still treated as a string. I also tried...
'description' => new Zend_XmlRpc_Value_Base64($row->body),
...however that still seems to end up being sent as a string when
it should presumably be wrapped in the <base64> element so that the
receiving end knows how to treat it. Is there a way to specify
types within an array to be struct'd ?
I then wondered if perhaps it was an encoding issue as I see
strings are htmlentitie-d with UTF-8 so I tried setting the
response as UTF-8 but still no luck.
Just to clarify:
The html (not full html since it's just part of the page) data is
being pulled from a MySQL field "body" of type "text" and added to
the array. The rendered html shows up fine for all rows if I call
the function directly ($metaweblog->getRecentPosts/getPost) but if
called via the xmlrpc server 6 out of the 39 samples come out as
empty strings.
Having failed with all my attempts to narrow this down so far I'd
appreciate any clues you may have as to where to look really. I've
been scouring the various Zend_XmlRpc_Value_* classes but not found
any specific reason so far.
Thanks for your help so far,
Nick
Aha, just managed to find out the reasons for the disappearing html
segments: rogue characters from Microsoft Word.
I was using html segments that had been composed with text pasted
from a Word document by the client. The 6 that failed had various
rogue characters (e.g. the smart quotes etc). Removing them fixed
everything up.
Of course I'll need to try and filter these out at the data entry
stage. Whether the xml-rpc process needs to account for/guard against
these issues is another thing.
Thanks again,
Nick