LXML: can't register namespace

Andrew Z formisc at gmail.com
Fri Mar 9 21:37:23 EST 2018


Stefan,
 thank you for the link. That explains the line of thinking of the package
designer(s).
I also looked@ beautifulsoup and found it to work better with my old brains.

On Fri, Mar 9, 2018 at 9:46 AM, Stefan Behnel <stefan_ml at behnel.de> wrote:

> Peter Otten schrieb am 09.03.2018 um 14:11:
> > 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.
> >
> > Does that mean the OP shouldn't use register_namespace() at all or that
> he's
> > supposed to replace "" with None?
>
> It meant neither of the two, but now that you ask, I would recommend the
> first. ;)
>
> An application global setup for the default namespace is never a good idea,
> thus my question regarding the actual intention of the OP. Depending on the
> context, the right thing to do might be be to either not care at all, or to
> not use the default namespace but a normally prefixed one instead, or to
> define a (default) namespace mapping for a newly created tree, as shown in
> the namespace tutorial.
>
> http://lxml.de/tutorial.html#namespaces
>
> Usually, not caring about namespace prefixes is the best approach. Parsers,
> serialisers and compressors can deal with them perfectly and safely, humans
> should just ignore the clutter, pitfalls and complexity that they
> introduce.
>
> Stefan
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list