Python program to remove comments from file

from lxml import tree
XML = """<root>
   <!-- COMMENT 1 -->
   <x>Hello</x>
   <y>World
      <!-- COMMENT 2 -->
   </y>
</root>"""
tree1 = tree.fromstring(XML)
comments = tree1.xpath('//comment()')
for c in comments:
p = c.getparent()
p.remove(c)
print tree.tostring(tree)

Output:

<root>
   <x>Hello</x>
   <y>World </y>
</root>