Improve loading of malformed XForms

http://manage.dimagi.com/default.asp?142079
http://manage.dimagi.com/default.asp?142193

Note that the XML in case 142079 is so badly malformed that it still does not load, but many of the loading problems have been solved by this PR.
Gets https://github.com/dimagi/XMLWriter/commit/ab8760d6e03925c67e3405123648291e1258ef40