code: public static String filterXML(String str) {
      String s = str;       
      if (s.contains("<")) { // don't run slow regex unless we have to
        s = XML_COMMENT_PATTERN.matcher(s).replaceAll(" ");
        s = XML_PATTERN.matcher(s).replaceAll("");
      }
      return s;
    }
docs: Simple XML filtering for XML tags.
  @param str XML string to be filtered.
  @return Filtered string without XML tags.