Message147380
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 |
|
Date |
User |
Action |
Args |
2011-11-09 23:22:49 | Nekmo | set | recipients:
+ Nekmo, jcea, flox |
2011-11-09 23:22:49 | Nekmo | set | messageid: <1320880969.81.0.336488235094.issue13378@psf.upfronthosting.co.za> |
2011-11-09 23:22:49 | Nekmo | link | issue13378 messages |
2011-11-09 23:22:48 | Nekmo | create | |
|