Fix XML serialisation with incorrect encoding #1741

If encoding is not explicitly defined, system default encoding is used
with incorrect XML declaration.