Here you create an el
element (no namespace):
xml1 = etree.Element('el', nsmap={None: "some_namespace"})
Using a nsmap
parameter does not bind the element to a namespace; it just provides a mapping for serialization.
When etree.tostring(xml1)
is executed, the serialization behaviour "kicks in". When the serialized result has been parsed, xml2
is an {some_namespace}el
element instead of el
.
To make it work, change the line to:
xml1 = etree.Element('{some_namespace}el', nsmap={None: "some_namespace"})