The result of MessageUnit.toXml may not be a well-formed Xml-Document, if the content includes characters as '<' or \000.
The C++ MessageUnit.toXml() and Java MsgUnit.toXml() methods are mainly for logging. They are not used operational.
The Java variant uses a CDATA section:
<content><![CDATA[BlaBlaBla]]></content>
which helps a bit but still may fail with binary contents containing ']]>' or '<