[lxml-dev] How to set an attribute with a xml-namepace

jholg at gmx.de jholg at gmx.de
Tue Apr 28 15:50:25 CEST 2009


Hi,

>  >>   xml = "<root xml:space=\"preserve\"/>"
>  >>   root = etree.fromstring(xml)
>  >>   print etree.tostring(root)
>  <root xml:space="preserve"/>
> 
> everything fine, and now...
> 
> >> root = etree.Element("root", space="preserve")
> >> print etree.tostring(root)
> <root space="preserve"/>

>>> root = etree.Element("root", attrib={'{http://www.w3.org/XML/1998/namespace}space': 'preserve'})
>>> print etree.tostring(root)
<root xml:space="preserve"/>
>>>

Cheers,
Holger
-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger01


More information about the lxml-dev mailing list