Fix XML parsing so that all valid encodings are supported

Implemented requested changes (from #140), I hope I didn't miss anything.