]> granicus.if.org Git - python/commitdiff
Don't get fooled by an empty prefix with a valid namespaceURI -- in
authorGuido van Rossum <guido@python.org>
Mon, 5 Feb 2001 18:50:15 +0000 (18:50 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 5 Feb 2001 18:50:15 +0000 (18:50 +0000)
this case, the code used to generate invalid tags and attribute names
with a leading colon, e.g. <:tag> or <tag :attr="foo">.

Lib/xml/dom/pulldom.py

index 66794f34e3f76b458338b933d4501ba6dfbcdd58..c400742e42305a06683c6a91b9503a878ca93961 100644 (file)
@@ -56,7 +56,11 @@ class PullDOM(xml.sax.ContentHandler):
             # provide us with the original name. If not, create
             # *a* valid tagName from the current context.
             if tagName is None:
-                tagName = self._current_context[uri] + ":" + localname
+                prefix = self._current_context[uri]
+                if prefix:
+                    tagName = prefix + ":" + localname
+                else:
+                    tagName = localname
             node = self.document.createElementNS(uri, tagName)
         else:
             # When the tagname is not prefixed, it just appears as
@@ -66,7 +70,11 @@ class PullDOM(xml.sax.ContentHandler):
         for aname,value in attrs.items():
             a_uri, a_localname = aname
             if a_uri:
-                qname = self._current_context[a_uri] + ":" + a_localname
+                prefix = self._current_context[a_uri]
+                if prefix:
+                    qname = prefix + ":" + a_localname
+                else:
+                    qname = a_localname
                 attr = self.document.createAttributeNS(a_uri, qname)
             else:
                 attr = self.document.createAttribute(a_localname)