[issue13378] Change the variable "nsmap" from global to instance (xml.etree.ElementTree)

Nekmo report at bugs.python.org
Thu Nov 10 00:22:49 CET 2011


Nekmo <nintux at gmail.com> added the comment:

In my case, I have several clients, and they define the namespaces. I am interested in return the same namespace that they gave me, for example, the client "A" gives me this:

<house:iq xmlns:house="http://localhost/house" />

To name the namespace, I set it at nsmap:

>>> import xml.etree.ElementTree as etree
>>> etree.register_namespace('house', 'http://localhost/house')
>>> etree._namespace_map
{'http://localhost/house': 'house',
 'http://purl.org/dc/elements/1.1/': 'dc',
 'http://schemas.xmlsoap.org/wsdl/': 'wsdl',
 'http://www.w3.org/1999/02/22-rdf-syntax-ns#': 'rdf',
 'http://www.w3.org/1999/xhtml': 'html',
 'http://www.w3.org/2001/XMLSchema': 'xs',
 'http://www.w3.org/2001/XMLSchema-instance': 'xsi',
 'http://www.w3.org/XML/1998/namespace': 'xml'}

Thus, keeping the name of the namespace:
>>> etree.tostring(etree.Element('{http://localhost/house}iq'))
b'<house:iq xmlns:house="http://localhost/house" />'

But if I have a client "B", which uses a different name, and run in parallel, problems can occur:

<home:iq xmlns:home="http://localhost/house" />

>>> import xml.etree.ElementTree as etree
>>> etree.register_namespace('home', 'http://localhost/house')
>>> etree._namespace_map
{'http://localhost/house': 'home',
 'http://purl.org/dc/elements/1.1/': 'dc',
 'http://schemas.xmlsoap.org/wsdl/': 'wsdl',
 'http://www.w3.org/1999/02/22-rdf-syntax-ns#': 'rdf',
 'http://www.w3.org/1999/xhtml': 'html',
 'http://www.w3.org/2001/XMLSchema': 'xs',
 'http://www.w3.org/2001/XMLSchema-instance': 'xsi',
 'http://www.w3.org/XML/1998/namespace': 'xml'}

Therefore, I ask that _namespace_map is within etree._Element instance, and not global

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13378>
_______________________________________


More information about the Python-bugs-list mailing list