@Test public void testEscapeXml() { Assert.assertEquals(StringEscapeHelper.escapeXml(""), ""); Assert.assertEquals(StringEscapeHelper.escapeXml("Test string without XML."), "Test string without XML."); Assert.assertEquals(StringEscapeHelper.escapeXml("Testing & character"), "Testing &amp; character"); Assert.assertEquals(StringEscapeHelper.escapeXml("Testing \" character"), "Testing &#034; character"); Assert.assertEquals(StringEscapeHelper.escapeXml("Testing &,:'<;> characters"), "Testing &amp;,:&#039;&lt;;&gt; characters"); Assert.assertEquals(StringEscapeHelper.escapeXml("double escape: &amp;,:&#039;&lt;;&gt;"), "double escape: &amp;amp;,:&amp;#039;&amp;lt;;&amp;gt;"); Assert.assertEquals( StringEscapeHelper.escapeXml("<xml><inner attr=\"test\">content</inner></xml>"), "&lt;xml&gt;&lt;inner attr=&#034;test&#034;&gt;content&lt;/inner&gt;&lt;/xml&gt;"); }
public static String escapeXml(String buffer) { int length = buffer.length(); char[] arrayBuffer = buffer.toCharArray(); StringBuilder escapedBuffer = new StringBuilder(length + 5); for (int i = 0; i < length; i++) { char c = arrayBuffer[i]; if (c <= '>') { switch (c) { case '>': escapedBuffer.append("&gt;"); break; case '<': escapedBuffer.append("&lt;"); break; case '&': escapedBuffer.append("&amp;"); break; case '"': escapedBuffer.append("&#034;"); break; case '\'': escapedBuffer.append("&#039;"); break; default: escapedBuffer.append(c); break; } } else { escapedBuffer.append(c); } } return escapedBuffer.toString(); }
StringEscapeHelper { public static String escapeXml(String buffer) { int length = buffer.length(); char[] arrayBuffer = buffer.toCharArray(); StringBuilder escapedBuffer = new StringBuilder(length + 5); for (int i = 0; i < length; i++) { char c = arrayBuffer[i]; if (c <= '>') { switch (c) { case '>': escapedBuffer.append("&gt;"); break; case '<': escapedBuffer.append("&lt;"); break; case '&': escapedBuffer.append("&amp;"); break; case '"': escapedBuffer.append("&#034;"); break; case '\'': escapedBuffer.append("&#039;"); break; default: escapedBuffer.append(c); break; } } else { escapedBuffer.append(c); } } return escapedBuffer.toString(); } }
StringEscapeHelper { public static String escapeXml(String buffer) { int length = buffer.length(); char[] arrayBuffer = buffer.toCharArray(); StringBuilder escapedBuffer = new StringBuilder(length + 5); for (int i = 0; i < length; i++) { char c = arrayBuffer[i]; if (c <= '>') { switch (c) { case '>': escapedBuffer.append("&gt;"); break; case '<': escapedBuffer.append("&lt;"); break; case '&': escapedBuffer.append("&amp;"); break; case '"': escapedBuffer.append("&#034;"); break; case '\'': escapedBuffer.append("&#039;"); break; default: escapedBuffer.append(c); break; } } else { escapedBuffer.append(c); } } return escapedBuffer.toString(); } private  StringEscapeHelper(); }
StringEscapeHelper { public static String escapeXml(String buffer) { int length = buffer.length(); char[] arrayBuffer = buffer.toCharArray(); StringBuilder escapedBuffer = new StringBuilder(length + 5); for (int i = 0; i < length; i++) { char c = arrayBuffer[i]; if (c <= '>') { switch (c) { case '>': escapedBuffer.append("&gt;"); break; case '<': escapedBuffer.append("&lt;"); break; case '&': escapedBuffer.append("&amp;"); break; case '"': escapedBuffer.append("&#034;"); break; case '\'': escapedBuffer.append("&#039;"); break; default: escapedBuffer.append(c); break; } } else { escapedBuffer.append(c); } } return escapedBuffer.toString(); } private  StringEscapeHelper(); static String escapeJavaScript(String str); static String escapeJavaScriptInlineHtml(String str); static String escapeJsonInlineHtml(String str); static String escapeNonWordCharacters(String str); static String escapeXml(String buffer); static String getSingleLineTextFromXML(String html); static String removeHtmlMarkup(String str); static String removeXmlMarkup(String str); }
StringEscapeHelper { public static String escapeXml(String buffer) { int length = buffer.length(); char[] arrayBuffer = buffer.toCharArray(); StringBuilder escapedBuffer = new StringBuilder(length + 5); for (int i = 0; i < length; i++) { char c = arrayBuffer[i]; if (c <= '>') { switch (c) { case '>': escapedBuffer.append("&gt;"); break; case '<': escapedBuffer.append("&lt;"); break; case '&': escapedBuffer.append("&amp;"); break; case '"': escapedBuffer.append("&#034;"); break; case '\'': escapedBuffer.append("&#039;"); break; default: escapedBuffer.append(c); break; } } else { escapedBuffer.append(c); } } return escapedBuffer.toString(); } private  StringEscapeHelper(); static String escapeJavaScript(String str); static String escapeJavaScriptInlineHtml(String str); static String escapeJsonInlineHtml(String str); static String escapeNonWordCharacters(String str); static String escapeXml(String buffer); static String getSingleLineTextFromXML(String html); static String removeHtmlMarkup(String str); static String removeXmlMarkup(String str);  }