[lxml-dev] namespace strangeness in lxml 1.1

Eric Jahn eric at ejahn.net
Tue Jul 1 18:54:19 CEST 2008


On Tue, 2008-07-01 at 07:20 +0200, Stefan Behnel wrote:
> ... You are setting a namespace as attribute /value/ here, not as attribute
> /name/. ...

Stefan, thank you very much for the response. Yes, I am intending to set
the namespace in an attribute value (not attribute name) here as I am
creating an XML Schema Document with lxml, not an XML Instance Document.
I apologize for not clarifying that in my post. 

> 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 + "...")

No, I don't want the prefix resolved the the url, so I guess my only
option is to do something like the following and just pass the type
value a string with the namespace prefix explicity stated: 

child1 = etree.SubElement(root,NS2 + "secondelement", nsmap=NSMAP, type
= "NS2:someattribute")

I think the tutorial could benefit from a small section on creating
schema docs as opposed to instance docs.  I'd be happy to submit the
start of such a new section?  Would this be helpful?  I know it would
have saved me a little time...  Thanks again for your help! -Eric




More information about the lxml-dev mailing list