Better error handling when parsing XML