Added error handling to XML parser