Encoding fix and fixing invalid XML structure