This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Martin Hosken
Recipients Martin Hosken
Date 2018-09-07.06:10:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1536300616.73.0.56676864532.issue34600@psf.upfronthosting.co.za>
In-reply-to
Content
This is a regression from python2 by being forced to use cElementTree.

I have code that uses iterparse to process an XML file, but I also want to process comments and so I have a comment handling function called by the parser during iterparse. Under python3 I can find no way to achieve the same thing:

```
parser = et.XMLParser(target=et.TreeBuilder())
parser.parser.CommentHandler = myCommentHandler
for event, elem in et.iterparse(fh, parser=parser):
    ...
```

Somewhat ugly but works in python2, but I can find no way to set a comment handler on the parser in python3.


1. There is no way(?) to get to xml.etree.ElementTree.XMLParser since the C implementation completely masks the python versions.
2. It is possible to create a subclass of TreeBuilder to add a comment method. But the C version XMLParser requires that its TreeBuilder not be a subclass, when used in iterparse.

The only solution I found was to copy the XMLParser code out of ElementTree into a private module and use that pure python implementation.

Suggested solutions:
1. Allow access to all the python implementations in ElementTree and not just Element.
2. Allow a comments method to be passed to the XMLParser on creation.

Thank you.
History
Date User Action Args
2018-09-07 06:10:16Martin Hoskensetrecipients: + Martin Hosken
2018-09-07 06:10:16Martin Hoskensetmessageid: <1536300616.73.0.56676864532.issue34600@psf.upfronthosting.co.za>
2018-09-07 06:10:16Martin Hoskenlinkissue34600 messages
2018-09-07 06:10:15Martin Hoskencreate