2) use the new QXmlStreamWriter class which generates XML files, automatically encoding what is needed
See QXmlStreamWriter::writeCharacters() and QXmlStreamWriter::writeCDATA().
This seems to be exactly what I need ! Thanks a lot.

Probably it was overlooked by me and others since it has appeared only in 4.3