Ben Martin wrote:
Hi,
  Given arbitrary data in a std::string what is the recommended way to
turn that into a CDATA node when building a DOM?


What do you mean by arbitrary data? If you mean characters that are not allowed in XML documents, then you must encode them somehow. You might consider using base64, for example.

string mystr = ...;
XMLCh* xch = XMLString::transcode( mystr.c_str() );

Using XMLString::transcode() to convert "arbitrary" data to UTF-16 presumes the local code page is a single byte encoding that contains a character at every code point, and that each of those characters maps to a Unicode code point.

DOMElement* el = ...;
DOMCDATASection* childVal = dom->createCDATASection( xch );
el->appendChild( childVal );

It seems to be difficult to preserve arbitrary 8 bit data from a
std::string into a CDATA definition.

I think you really want to use something like base64. That way, you don't even need to use a CDATA section.

Dave

Reply via email to