[lxml-dev] namespace strangeness in lxml 1.1

Stefan Behnel stefan_ml at behnel.de
Tue Jul 1 07:20:54 CEST 2008


Hi,

Eric Jahn wrote:
> type="{http://domain2.info}someattribute
>
> element = etree.Element(NS2 + "secondelement", nsmap=NSMAP, type = NS2 +
> "someattribute")

You are setting a namespace as attribute /value/ here, not as attribute
/name/. lxml will not modify content unless you tell it to do so. If you want
it to replace the namespace by a resolved prefix, use

    type = etree.QName(NS2 + "...")

If it's just a mistake and you wanted to set the attribute /namespace/
instead, pass

    attrib = {NS2 + "someattribute" : "somevalue"}

to the Element factory. There should also be a section on this in the tutorial
IIRC.

Stefan


More information about the lxml-dev mailing list