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

Grimm, Markus Grimm at juris.de
Tue Apr 28 14:32:06 CEST 2009


Hi all,

I want to set a new element with an attribute using the xml-namespace,
f.e.

 >>   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"/>

How can I bind the space-attribute to the xml-namespace, so I can output
the same result as above ?

Thanks,
Markus





More information about the lxml-dev mailing list