Escape XML snippets with CDATA sections

Technique taken from <http://stackoverflow.com/q/12388800/449288>, but
it does not seem to work properly.