Added error checking to parseToDom. XML is a pain in the arse in the browser...