[lxml-dev] Pb with namespaces on attributs

Stefan Behnel stefan_ml at behnel.de
Wed Nov 14 23:32:34 CET 2007


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




More information about the lxml-dev mailing list