How to send message body in CDATA with strophe?
-
09-12-2019 - |
Question
I am generating messages like this
$msg({to: 'user', from: 'me', type: 'chat'}).c("body").t('some data');
that generates:
<message to='user' from='me' type='chat' xmlns='jabber:client'>
<body>some data</body>
</message>
but I need this:
<message to='user' from='me' type='chat' xmlns='jabber:client'>
<body><![CDATA[some data]]></body>
</message>
do strophejs
have something or do I need generate them myself? Is it even possible send CDATA to XMPP?
Solution
You can send CDATA, but I don't think you need to care about it in this case. Just pass the stringified data to the .t()
method and it should take care of escaping it.
There's also no guarantee that CDATA will continue to be CDATA all the way, at least one server re-serializes it as a normal text node with &escaped;
entities.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow