Emit XML entities for &, ", < and >

Also convert instances of `\\n` (i.e. a backslash followed by an n) that were being inserted instead of newlines.