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 amaury.forgeotdarc
Recipients amaury.forgeotdarc, effbot, poke
Date 2010-04-01.09:01:49
SpamBayes Score 0.005573557
Marked as misclassified No
Message-id <1270112511.48.0.571492825321.issue8277@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2010-04-01 09:01:51amaury.forgeotdarcsetrecipients: + amaury.forgeotdarc, effbot, poke
2010-04-01 09:01:51amaury.forgeotdarcsetmessageid: <1270112511.48.0.571492825321.issue8277@psf.upfronthosting.co.za>
2010-04-01 09:01:50amaury.forgeotdarclinkissue8277 messages
2010-04-01 09:01:49amaury.forgeotdarccreate