How to replace HTML comments with custom <comment> elements
问题 I'm working on mass-converting a number of HTML files to XML using BeautifulSoup in Python. A sample HTML file looks something like this: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!-- this is an HTML comment --> <!-- this is another HTML comment --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> ... <!-- here is a comment inside the head tag --> </head> <body> ... <!-- Comment inside body tag --> <!-- Another