Improved workaround for buggy libxml/DOM behavior with namespaced attributes in HTML parsing mode, closes #651 and fixes #650