I am trying to remove comment tags from local .xml files using the BeautifulSoup library.
sample XML
<?xml version="1.0" encoding="UTF-8"?>
<note>
<!-- remove this -->
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
python
from bs4 import BeautifulSoup as BS
from bs4 import Comment
soup = BS(open("sample.xml"))
comments=soup.find_all(string=lambda text:isinstance(text,Comment))
for c in comments:
c.decompose()
When I run this code I get the following error:
AttributeError: 'Comment' object has no attribute 'decompose'
I am not sure why I am getting this error.