Fix XML encoding issues

Closes #1578