Merge with PyXML 1.82:
Correct various typos. Fixes #674700.
Set newly created attribute via setNamedItem.
diff --git a/Lib/xml/dom/minidom.py b/Lib/xml/dom/minidom.py
index 46eb881..2ec4325 100644
--- a/Lib/xml/dom/minidom.py
+++ b/Lib/xml/dom/minidom.py
@@ -16,7 +16,7 @@
 
 import xml.dom
 
-from xml.dom import EMPTY_NAMESPACE, EMPTY_PREFIX
+from xml.dom import EMPTY_NAMESPACE, EMPTY_PREFIX, XMLNS_NAMESPACE, domreg
 from xml.dom.minicompat import *
 from xml.dom.xmlbuilder import DOMImplementationLS, DocumentLS
 
@@ -384,10 +384,10 @@
         else:
             d[name] = value
 
-    def _set_prefix(self, value):
+    def _set_prefix(self, prefix):
         nsuri = self.namespaceURI
-        if value == "xmlns":
-            if self.namespaceURI and self.namespaceURI != XMLNS_NAMESPACE:
+        if prefix == "xmlns":
+            if nsuri and nsuri != XMLNS_NAMESPACE:
                 raise xml.dom.NamespaceErr(
                     "illegal use of 'xmlns' prefix for the wrong namespace")
         d = self.__dict__
@@ -395,7 +395,7 @@
         if prefix is None:
             newName = self.localName
         else:
-            newName = "%s:%s" % (value, self.localName)
+            newName = "%s:%s" % (prefix, self.localName)
         if self.ownerElement:
             _clear_id_cache(self.ownerElement)
         d['nodeName'] = d['name'] = newName
@@ -536,6 +536,7 @@
             except KeyError:
                 node = Attr(attname)
                 node.ownerDocument = self._ownerElement.ownerDocument
+                self.setNamedItem(node)
             node.value = value
         else:
             if not isinstance(value, Attr):
@@ -1008,7 +1009,8 @@
 class Text(CharacterData):
     # Make sure we don't add an instance __dict__ if we don't already
     # have one, at least when that's possible:
-    __slots__ = ()
+    # XXX this does not work, CharacterData is an old-style class
+    # __slots__ = ()
 
     nodeType = Node.TEXT_NODE
     nodeName = "#text"
@@ -1132,7 +1134,8 @@
 class CDATASection(Text):
     # Make sure we don't add an instance __dict__ if we don't already
     # have one, at least when that's possible:
-    __slots__ = ()
+    # XXX this does not work, Text is an old-style class
+    # __slots__ = ()
 
     nodeType = Node.CDATA_SECTION_NODE
     nodeName = "#cdata-section"
@@ -1212,7 +1215,8 @@
 class Identified:
     """Mix-in class that supports the publicId and systemId attributes."""
 
-    __slots__ = 'publicId', 'systemId'
+    # XXX this does not work, this is an old-style class
+    # __slots__ = 'publicId', 'systemId'
 
     def _identified_mixin_init(self, publicId, systemId):
         self.publicId = publicId