Message102078
ElementTree does parse comments, it just omit them in the tree.
A quick search lead me to this page: http://effbot.org/zone/element-pi.htm
which can be further simplified:
from xml.etree import ElementTree
class MyTreeBuilder(ElementTree.TreeBuilder):
def comment(self, data):
self.start(ElementTree.Comment, {})
self.data(data)
self.end(ElementTree.Comment)
with open('c:/temp/t.xml', 'r') as f:
xml = ElementTree.parse(
f, parser=ElementTree.XMLParser(target=MyTreeBuilder()))
ElementTree.dump(xml)
Now, should ElementTree do this by default? It's not certain, see how effbot's sample needs to wrap the entire file into another 'document' element. |
|
Date |
User |
Action |
Args |
2010-04-01 09:01:51 | amaury.forgeotdarc | set | recipients:
+ amaury.forgeotdarc, effbot, poke |
2010-04-01 09:01:51 | amaury.forgeotdarc | set | messageid: <1270112511.48.0.571492825321.issue8277@psf.upfronthosting.co.za> |
2010-04-01 09:01:50 | amaury.forgeotdarc | link | issue8277 messages |
2010-04-01 09:01:49 | amaury.forgeotdarc | create | |
|