code: public static String escapeForXML(String str) {
          StringBuilder sb = new StringBuilder(str.length());
  
          for (int i = 0; i < str.length(); i++) {
              char c = str.charAt(i);
  
              boolean foundEscape = false;
              for (int j = 0; j < toBeEscaped.length; j++) {
                  if (c == toBeEscaped[j]) {
                      sb.append(escaped[j]);
                      foundEscape = true;
                      break;
                  }
              }
  
              if (!foundEscape) {
                  sb.append(c);
              }
          }
          return sb.toString();
      }
docs: escape 5 special chars http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references