Author Aaron.Oakley
Recipients Aaron.Oakley, docs@python, eli.bendersky, python-dev
Date 2013-08-27.02:11:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1377569480.34.0.0904623844155.issue17902@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2013-08-27 02:11:20Aaron.Oakleysetrecipients: + Aaron.Oakley, eli.bendersky, docs@python, python-dev
2013-08-27 02:11:20Aaron.Oakleysetmessageid: <1377569480.34.0.0904623844155.issue17902@psf.upfronthosting.co.za>
2013-08-27 02:11:20Aaron.Oakleylinkissue17902 messages
2013-08-27 02:11:19Aaron.Oakleycreate