Message body contains &lt; and &gt; instead of < and >

Hi all,

Started using openfire recently and made a component plugin that communicates with other openfire components.

The components uses Message packets that contain XML in the body to share information.

I’ve noticed that the “<” and “>” in the message body are being converted into HTML somehow before being sent.

The receiving component gets < instead of < and > instead of >, and is unable to work with the message.

Is there a way to stop this conversion?

Thanks in advance,


Having the same issue. I think it’s because the backing Element automatically escapes anything provided to it with setText(), and addCDATA() isn’t doing the trick either.

The general question, I suppose, is how we get arbitrary XML into a Message. Anybody know?

Is there a way to stop this conversion?
No. XMPP does transmit data in XML format. In XML you must not use < and > symbols. Several other symbols need also be escaped. However, its a bijective mapping: Simply replace all occurrences of < with <, all occurrences of > with > and so on.

See also StringUtils.escapeForXML(String) and StringUtils.unescapeFromXML(String)

I must have woken up on the stupid side of the bed that morning.

If you want to mix text and XML elements inside another element, what you want is for the element to have mixed content, not text content. setText() assumes the entire body of the element is plain text, so escaping characters is always correct behavior. To mix text and elements, you need to add Text nodes and Element nodes with add().

Hope this helps the next person who gets confused.

I used StringUtils.unescapeFromXML(string) to convert the < and > to < and >.

Thank for the help.