Wrapped up removing/replacing illegal XML characters in to functions.
Replaced writeData with writeData2