$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from lxml import etree
>>> a = etree.fromstring("""<a xmlns="A"/>""")
>>> b = etree.fromstring("""<b/>""")
>>> a.append(b)
>>> etree.tostring(a)
b'<a xmlns="A"><b/></a>'
>>> etree.tostring(b)
b'<b xmlns="A"/>'
Note the inserted element appears to "adopt" the namespace of the parent when being serialized. It seems to take on the parent's namespace map without taking into account that the prefix (or lack thereof) is reused:
Is this issue caused by the same bug?:
$ python3 g("""<a xmlns="A"/>""") g("""<b/ >""")
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from lxml import etree
>>> a = etree.fromstrin
>>> b = etree.fromstrin
>>> a.append(b)
>>> etree.tostring(a)
b'<a xmlns="A"><b/></a>'
>>> etree.tostring(b)
b'<b xmlns="A"/>'
Note the inserted element appears to "adopt" the namespace of the parent when being serialized. It seems to take on the parent's namespace map without taking into account that the prefix (or lack thereof) is reused:
# Continuing from above...
>>> a.tag
'{A}a'
>>> b.tag
'b'
>>> a.nsmap
{None: 'A'}
>>> b.nsmap
{None: 'A'}