Salut encore,
Xavier Morel schrieb am 04.03.22 um 12:58:
lxml provides support for custom Element classes (as well as element-ish
e.g. Comment or PI) via the `ElementDefaultClassLookup` registry, and the
ability to hook it into a parser.
But that registry does not seem to have a slot for the root tree of the
elements. Is there a hook somewhere to set *that*? I tried looking around
the API docs but nothing really jumped out.
Do you really need something like that? Can't you just inherit from the
ElementTree class? (Assuming that's what you meant.)
The reason why you can register your own Element classes is because they
can appear all over the place in the API. The ElementTree class is either
instantiated by the user or returned from the parse() function. That's
mostly it. Ok, maybe XSLT. But still easy enough to wrap yourself.
PS: the documentation for `set_default_parser` explains that it sets the
default parser *for the current thread* and that "You can create a separate
parser for each thread explicitly or use a parser pool.", does
it mean that in a "don't call any API which gets an implicit parser and
manage your parsers by hand" sense or something else?
Parsers are really only used where an explicit "parser" argument is
accepted. Everything else just inherits them. If you want to use your own
parser, write a wrapper function for parse() that always passes it in, and
then use that function instead.
Stefan
_______________________________________________
lxml - The Python XML Toolkit mailing list -- lxml@python.org
To unsubscribe send an email to lxml-le...@python.org
https://mail.python.org/mailman3/lists/lxml.python.org/
Member address: arch...@mail-archive.com