Yes, in your top-most document make the CDATA section of data type bin.base64. That way even if the document you're wrapping contains a CDATA section, you're protected. As an added bonus, your application will also support binary files (images, spreadsheets, etc.).
Here's some code that does it, based on Microsoft ADO, and MSXML.
function wrapBinaryFile( strFileName)
{
var ado_stream = new ActiveXObject("ADODB.Stream");
var xml = newXMLDocument();
xml.loadXML("<file/>");
xml.documentElement.setAttribute( "name", strFileName );
xml.documentElement.setAttribute("xmlns:dt","urn:schemas-microsoft-com:datatypes");
xml.documentElement.dataType = "bin.base64";
ado_stream.Type = 1; // 1=adTypeBinary
ado_stream.Open();
ado_stream.LoadFromFile( strFileName );
xml.documentElement.nodeTypedValue = ado_stream.Read(-1); // -1=adReadAll
ado_stream.Close();
return xml;
}
And how to un-wrap it on the other end...
function unwrapBinaryFile(ndFile, strFileName )
{
var ado_stream = new ActiveXObject("ADODB.Stream");
ndFile.dataType = "bin.base64";
ado_stream.Type = 1; // 1=adTypeBinary
ado_stream.Open();
ado_stream.write( ndFile.nodeTypedValue );
ado_stream.SaveToFile( strFileName, 2 );
ado_stream.Close();
}