How to remove comments from an XML file?

I would do it in this way:

cat myfile.xml | sed '/<!--.*-->/d' | sed '/<!--/,/-->/d' > cleaned.xml

Or:

awk 'in_comment&&/-->/{sub(/([^-]|-[^-])*--+>/,"");in_comment=0}
 in_comment{next}
 {gsub(/<!--+([^-]|-[^-])*--+>/,"");
  in_comment=sub(/<!--+.*/,"");
  print}'

Or:

xmlstarlet ed -d '//comment()' file.xml