Amaury Forgeot d'Arc <[email protected]> added the comment:
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.
----------
nosy: +amaury.forgeotdarc, effbot
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue8277>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com