XmlSanitizer { public static String escapeXml(final String s) { if (s == null) return ""; String result; result = s.replaceAll("&","&amp;"); result = result.replaceAll("<","&lt;"); result = result.replaceAll(">","&gt;"); result = result.replaceAll("\"","&quot;"); result = result.replaceAll("'","&apos;"); return result; }  static String sanitize(final String input, final String tag); static String escapeXml(final String s); static String unescapeXml(final String s);  }
@Test public void escapeAllSupported() { String sanitized = XmlSanitizer.escapeXml(allUnsafeChars); assertThat(sanitized, is(equalTo(allSanitizedChars))); }