[lxml-dev] Pb with namespaces on attributs
An attribut of a node, inserted then removed from a tree, can lose its namespace :
from lxml import etree as ET parent = ET.Element('parent') parent.set('{http://foo/bar}x', 'a') child = ET.SubElement(parent, 'child') child.set('{http://foo/bar}x', 'b')
print ET.tostring(child), child.nsmap <child xmlns:ns0="http://foo/bar" ns0:x="b"/> {'ns0': 'http://foo/bar'}
child = parent[0] parent.clear() print ET.tostring(child), child.nsmap <child x="b"/> {}
It happends when the tree already knows the namespace used. A bug in lxml or in libxml2 (tested with lxml-2.0alpha4 and libxml2 2.6.28 / 2.6.30) ?
Alain Poirier wrote:
An attribut of a node, inserted then removed from a tree, can lose its namespace :
from lxml import etree as ET parent = ET.Element('parent') parent.set('{http://foo/bar}x', 'a') child = ET.SubElement(parent, 'child') child.set('{http://foo/bar}x', 'b')
print ET.tostring(child), child.nsmap <child xmlns:ns0="http://foo/bar" ns0:x="b"/> {'ns0': 'http://foo/bar'}
child = parent[0] parent.clear() print ET.tostring(child), child.nsmap <child x="b"/> {}
It happends when the tree already knows the namespace used.
Thanks for the report. This is a serialisation bug that was already fixed in lxml 1.3.5 and on the current SVN trunk. The fix will be in 2.0alpha5. Stefan
participants (2)
-
Alain Poirier
-
Stefan Behnel