Message324719
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. |
|
Date |
User |
Action |
Args |
2018-09-07 06:10:16 | Martin Hosken | set | recipients:
+ Martin Hosken |
2018-09-07 06:10:16 | Martin Hosken | set | messageid: <1536300616.73.0.56676864532.issue34600@psf.upfronthosting.co.za> |
2018-09-07 06:10:16 | Martin Hosken | link | issue34600 messages |
2018-09-07 06:10:15 | Martin Hosken | create | |
|