[docs] [issue17902] Document that _elementtree C API cannot use custom TreeBuilder for iterparse or IncrementalParser

Eli Bendersky report at bugs.python.org
Tue Aug 27 05:41:41 CEST 2013


Eli Bendersky added the comment:

On Mon, Aug 26, 2013 at 7:11 PM, Aaron Oakley <report at bugs.python.org>wrote:

>
> Aaron Oakley added the comment:
>
> >From memory, the use case at the time was using a custom TreeBuilder
> sub-class fed into a builtin XMLParser object. The code would construct a
> builder separately and keep a reference to it around. The builder would
> delegate calls to start(), data(), end(), and close() to super and save the
> completed tree when its close() was called.
>
>     my_builder = CustomTreeBuilder()
>     et_parser = ET.XMLParser(target=my_builder)
>
>     for (evt, elem) in ET.iterparse("...", events, parser=et_parser):
>         pass  # Do first processing
>
>     tree = my_builder.root  # Saved tree
>
> It was done like this initially so that some data (I can't recall exactly
> what) from the XML input could be processed first very conveniently using
> the parse events from iterparse while allowing the whole tree to be
> retrieved afterwards.
>
> That said, the project later moved to using lxml for various features not
> contained in xml.etree.ElementTree, and I don't think the process I
> described is still being used.
>

Thanks for the information, Aaron; much appreciated.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17902>
_______________________________________


More information about the docs mailing list