code: public static String escapeXml(String value) {
          // null to null
          if (value == null)
              return null;
  
          // assume the resulting string will be the same
          int len = value.length();
          StringBuilder buf = new StringBuilder(len);
  
          for (int i = 0; i < len; i++) {
              char c = value.charAt(i);
              boolean entityFound = false;
              // is this a matching entity?
              for (int j = 0; j < XML_CHARS.length; j++) {
                  // is this the matching character?
                  if (c == XML_CHARS[j][0].charAt(0)) {
                      // append the entity
                      buf.append(XML_CHARS[j][1]);
                      entityFound = true;
                  }
              }
              if (!entityFound) {
                  buf.append(c);
              }
          }
          return buf.toString();
      }
docs: Escapes the characters in a String using XML entities.
  For example: "bread" & "butter'ed" => &quot;bread&quot; &amp; &quot;butter&apos;ed&quot;
  
  Supports the five basic XML entities (gt, lt, quot, amp, apos) and also
  supports a newline and carriage return character.  A newline is escaped
  to &#10; and a carriage return to &#13;
  
  @param value The string to escape
  @return The escaped String that can be used in an XML document.