code: public static String getXMLValidString(final String input,
              final boolean replace, final char replacement) {
          if (input == null) {
              return null;
          }
  
          if ("".equals(input)) {
              return "";
          }
  
          StringBuilder sb = new StringBuilder();
          for (char c : input.toCharArray()) {
              if (XMLStringUtil.isXMLValid(c)) {
                  sb.append(c);
              } else if (replace) {
                  sb.append(replacement);
              }
          }
          return sb.toString();
      }
docs: Remove or replace XML invalid chars from input.
  
  @param input
  @param replace
  Whether or not to replace invalid characters by replacement
  @param replacement
  The character to replace any invalid character found
  @return The String that is cleaned from the invalid in XML characters.
  @see #isXMLValid(char)