Improve error handling on xml parse