Index: src/Scheme/Glue/build-glue-basic.scm
===================================================================
--- src/Scheme/Glue/build-glue-basic.scm	(revision 5584)
+++ src/Scheme/Glue/build-glue-basic.scm	(working copy)
@@ -229,6 +229,7 @@
   (tm->xml-cdata tm_to_xml_cdata (object string))
   (xml-name->tm xml_name_to_tm (string string))
   (old-xml-cdata->tm old_xml_cdata_to_tm (string string))
+  (xml-cdata->tm xml_cdata_to_tm (string string))
   (xml-unspace xml_unspace (string string bool bool))
   (integer->hexadecimal as_hexadecimal (string int))
   (integer->padded-hexadecimal as_hexadecimal (string int int))
Index: src/Scheme/Glue/glue_basic.cpp
===================================================================
--- src/Scheme/Glue/glue_basic.cpp	(revision 5584)
+++ src/Scheme/Glue/glue_basic.cpp	(working copy)
@@ -2593,6 +2593,19 @@
 }
 
 tmscm
+tmg_xml_cdata_2tm (tmscm arg1) {
+  TMSCM_ASSERT_STRING (arg1, TMSCM_ARG1, "xml-cdata->tm");
+
+  string in1= tmscm_to_string (arg1);
+
+  // TMSCM_DEFER_INTS;
+  string out= xml_cdata_to_tm (in1);
+  // TMSCM_ALLOW_INTS;
+
+  return string_to_tmscm (out);
+}
+
+tmscm
 tmg_xml_unspace (tmscm arg1, tmscm arg2, tmscm arg3) {
   TMSCM_ASSERT_STRING (arg1, TMSCM_ARG1, "xml-unspace");
   TMSCM_ASSERT_BOOL (arg2, TMSCM_ARG2, "xml-unspace");
@@ -6659,6 +6672,7 @@
   tmscm_install_procedure ("tm->xml-cdata",  tmg_tm_2xml_cdata, 1, 0, 0);
   tmscm_install_procedure ("xml-name->tm",  tmg_xml_name_2tm, 1, 0, 0);
   tmscm_install_procedure ("old-xml-cdata->tm",  tmg_old_xml_cdata_2tm, 1, 0, 0);
+  tmscm_install_procedure ("xml-cdata->tm",  tmg_xml_cdata_2tm, 1, 0, 0);
   tmscm_install_procedure ("xml-unspace",  tmg_xml_unspace, 3, 0, 0);
   tmscm_install_procedure ("integer->hexadecimal",  tmg_integer_2hexadecimal, 1, 0, 0);
   tmscm_install_procedure ("integer->padded-hexadecimal",  tmg_integer_2padded_hexadecimal, 2, 0, 0);
Index: src/Data/Convert/Xml/parsexml.cpp
===================================================================
--- src/Data/Convert/Xml/parsexml.cpp	(revision 5584)
+++ src/Data/Convert/Xml/parsexml.cpp	(working copy)
@@ -737,7 +737,7 @@
       // TODO: convert DTD declarations
       content << tuple ("*DOCTYPE*", simple_quote (t[i][1]->label));
     else if (is_tuple (t[i], "cdata"))
-      content << simple_quote (t[i][1]->label);
+      content << tuple ("raw-data", simple_quote (t[i][1]->label));
   if (N(attrs) > 1) tag << attrs;
   tag << A(content);
   return tag;
Index: src/Data/String/analyze.cpp
===================================================================
--- src/Data/String/analyze.cpp	(revision 5584)
+++ src/Data/String/analyze.cpp	(working copy)
@@ -445,14 +445,14 @@
 }
 
 object
-tm_to_xml_cdata (string s) {
+tm_to_xml_cdata (string s) { // FIXME? we convert to CharData, not CDATA
   array<object> a;
   a << symbol_object ("!concat");
   string r;
   int i, n= N(s);
   for (i=0; i<n; i++)
-    if (s[i] == '&') r << "&amp;";
-    else if (s[i] == '>') r << "&gt;";
+    if (s[i] == '&') r << "&amp;";      // checks neccesary? tm format
+    else if (s[i] == '>') r << "&gt;";  // already escapes & and >
     else if (s[i] == '\\') r << "\\";
     else if (s[i] != '<') r << cork_to_utf8 (s (i, i+1));
     else {
@@ -461,8 +461,14 @@
       string ss= s (start, i+1);
       string rr= cork_to_utf8 (ss);
       string qq= utf8_to_cork (rr);
-      if (rr != ss && qq == ss) r << rr;
-      else {
+      if (rr != ss && qq == ss) {
+        for (int j=0; j<N(rr); ++j) {
+          if (rr[j] == '<') r << "&lt;";
+          else if (rr[j] == '>') r << "&gt;";
+          else if (rr[j] == '&') r << "&amp;";
+          else r << rr[j];
+        }
+      } else {
 	if (r != "") a << object (r);
 	a << cons (symbol_object ("tm-sym"),
 		   cons (ss (1, N(ss)-1),
@@ -477,6 +483,23 @@
 }
 
 string
+xml_cdata_to_tm (string s) {
+  string r;
+  s = utf8_to_cork(s);
+  int i, n= N(s);
+  for (i=0; i<n; i++)
+    if (s[i] != '&') r << s[i];
+    else {
+      int start= ++i;
+      while ((i<n) && (s[i]!=';')) i++;
+      if (s (start, i) ==  "lt") r << "<less>";
+      else if (s (start, i) ==  "gt") r << "<gtr>";
+      else if (s (start, i) ==  "amp") r << "&";
+    }
+  return r;
+}
+
+string
 old_xml_cdata_to_tm (string s) {
   string r;
   int i, n= N(s);
Index: src/Data/String/analyze.hpp
===================================================================
--- src/Data/String/analyze.hpp	(revision 5584)
+++ src/Data/String/analyze.hpp	(working copy)
@@ -54,6 +54,7 @@
 string german_to_igerman (string s);
 string old_tm_to_xml_cdata (string s);
 object tm_to_xml_cdata (string s);
+string xml_cdata_to_tm (string s);
 string old_xml_cdata_to_tm (string s);
 string tm_to_xml_name (string s);
 string xml_name_to_tm (string s);
Index: TeXmacs/progs/convert/tmml/tmmltm.scm
===================================================================
--- TeXmacs/progs/convert/tmml/tmmltm.scm	(revision 5584)
+++ TeXmacs/progs/convert/tmml/tmmltm.scm	(working copy)
@@ -75,6 +75,7 @@
 	       (xmlin-special tag attrs args))
 	      ((list-or (map (lambda (x) (func? x 'tm-par)) args))
 	       (xmlin-special tag attrs args))
+        ((== tag 'raw-data) x)
 	      (else (xmlin-regular tag attrs args))))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -86,7 +87,7 @@
 (define (tmmltm-string s)
   (if (version-before? tmmltm-current-version "1.0.5.8")
       (old-xml-cdata->tm s)
-      (utf8->cork s)))
+      (xml-cdata->tm s)))
 
 (define (tmmltm-file version args)
   (with old-version tmmltm-current-version
@@ -159,6 +160,7 @@
 	((func? x '!document) (tmmltm-document (cdr x)))
 	((func? x '!concat) (tmmltm-concat (cdr x)))
 	((func? x 'with) (tmmltm-with x))
+  ((func? x 'raw-data) `(raw-data ,(cadr x)))
 	((and (func? x 'tm-sym 1) (string? (cadr x)))
 	 (string-append "<" (cadr x) ">"))
 	(else (tmmltm-regular (car x) (cdr x)))))
@@ -176,7 +178,7 @@
 
 (tm-define (tmml->texmacs tmml)
   (:type (-> stree stree))
-  (:synopsis "Convert an TeXmacs XML stree @s into TeXmacs.")
+  (:synopsis "Convert a TeXmacs XML stree @s into TeXmacs.")
   (with doc (tmmltm tmml)
     (if (func? doc '!file 1)
 	(tree->stree (upgrade-tmml (cadr doc)))
Index: TeXmacs/progs/convert/tmml/tmtmml.scm
===================================================================
--- TeXmacs/progs/convert/tmml/tmtmml.scm	(revision 5584)
+++ TeXmacs/progs/convert/tmml/tmtmml.scm	(working copy)
@@ -34,6 +34,9 @@
 (define (tmtmml-with l)
   (tmtmml-regular 'with (list (cons 'attr (cDr l)) (cAr l))))
 
+(define (tmtmml-raw-data l)
+  (string-append "<![CDATA[" (car l) "]]>")) ;FIXME: escape any ']]>' in l
+
 (define (tmtmml-args l)
   (cond ((null? l) l)
 	((and (null? (cdr l)) (!= (car l) "")) (list (tmtmml (car l))))
@@ -66,6 +69,7 @@
 	((func? x 'document) (tmtmml-document (cdr x)))
 	((func? x 'concat) (tmtmml-concat (cdr x)))
 	((func? x 'with) (tmtmml-with (cdr x)))
+  ((func? x 'raw-data) (tmtmml-raw-data (cdr x)))
 	((and (func? x 'compound) (string? (cadr x)))
 	 (tmtmml-apply (symbol->string (car x))
 		       (string->symbol (cadr x))
