Typically storing a document model within a document model is done either by escaping the document characters or storing it within a cdata section within the parent xml model. In PAM Escaping the DOM might be easier to do for you and so it might be possible to run it through a function like this:
function escapeXml(unsafe) {
return unsafe.replace(/[<>&'"]/g, function (c) {
switch (c) {
case '<': return '<';
case '>': return '>';
case '&': return '&';
case '\'': return ''';
case '"': return '"';
}
});
}