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 celinecyc
Recipients amaury.forgeotdarc, celinecyc, effbot, flox, poke, scoder
Date 2019-11-08.08:10:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1573200653.57.0.472898795822.issue38742@roundup.psfhosted.org>
In-reply-to
Content
issue8277
It couldn't work for those comments before the root element. 
It will raise an error that "xml.etree.ElementTree.ParseError: multiple elements on top level". 

Example:

test.xml
--------
<?xml version="1.0" encoding="utf-8"?>
<!-- comments here doesn't work -->
<root node>
  <nodeA />
  <!-- comments here is ok -->
  <nodeB />
</root node>

test.py
-------
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)
History
Date User Action Args
2019-11-08 08:10:53celinecycsetrecipients: + celinecyc, effbot, amaury.forgeotdarc, scoder, poke, flox
2019-11-08 08:10:53celinecycsetmessageid: <1573200653.57.0.472898795822.issue38742@roundup.psfhosted.org>
2019-11-08 08:10:53celinecyclinkissue38742 messages
2019-11-08 08:10:53celinecyccreate