LXML: can't register namespace

Stefan Behnel stefan_ml at behnel.de
Fri Mar 9 07:08:10 EST 2018


Steven D'Aprano schrieb am 09.03.2018 um 12:41:
> On Fri, 09 Mar 2018 10:22:23 +0100, Stefan Behnel wrote:
> 
>> Andrew Z schrieb am 07.03.2018 um 05:03:
>>> Hello,
>>>  with 3.6 and latest greatest lxml:
>>>
>>> from lxml import etree
>>>
>>> tree = etree.parse('Sample.xml')
>>> etree.register_namespace('','http://www.example.com')
>>
>> The default namespace prefix is spelled None (because there is no prefix
>> for it) and not the empty string.
> 
> Is that documented somewhere?

http://lxml.de/tutorial.html#namespaces


> Is there a good reason not to support "" as the empty prefix?

Well, the "empty prefix" is not an "empty" prefix, it's *no* prefix. The
result is not ":tag" instead of "prefix:tag", the result is "tag".

But even ignoring that difference, why should the API support two ways of
spelling the same thing, and thus encourage users to write diverging code?

Stefan




More information about the Python-list mailing list