@Test public void escapeUtf8() throws Exception { final String test = "Some string with <tag>tag</tag> & \"funky\" 'chars'\\text"; final StringBuilder xml = new StringBuilder(); AttributeXmlEntityHandler.appendEscapedXmlUtf8(xml, test); assertEquals("Some string with &lt;tag&gt;tag&lt;/tag&gt; &amp; &quot;funky&quot; &#039;chars&#039;\\text", xml.toString()); }
protected static void appendEscapedXmlUtf8(final StringBuilder toAppendTo, final String text){ if (text != null) { for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); switch (c) { case '<': toAppendTo.append("&lt;"); break; case '>': toAppendTo.append("&gt;"); break; case '"': toAppendTo.append("&quot;"); break; case '\'': toAppendTo.append("&#039;"); break; case '&': toAppendTo.append("&amp;"); break; default: toAppendTo.append(c); } } } }
AbstractXmlEntityHandler implements XmlEntityExportHandler<T> { protected static void appendEscapedXmlUtf8(final StringBuilder toAppendTo, final String text){ if (text != null) { for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); switch (c) { case '<': toAppendTo.append("&lt;"); break; case '>': toAppendTo.append("&gt;"); break; case '"': toAppendTo.append("&quot;"); break; case '\'': toAppendTo.append("&#039;"); break; case '&': toAppendTo.append("&amp;"); break; default: toAppendTo.append(c); } } } } }
AbstractXmlEntityHandler implements XmlEntityExportHandler<T> { protected static void appendEscapedXmlUtf8(final StringBuilder toAppendTo, final String text){ if (text != null) { for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); switch (c) { case '<': toAppendTo.append("&lt;"); break; case '>': toAppendTo.append("&gt;"); break; case '"': toAppendTo.append("&quot;"); break; case '\'': toAppendTo.append("&#039;"); break; case '&': toAppendTo.append("&amp;"); break; default: toAppendTo.append(c); } } } } protected  AbstractXmlEntityHandler(final String rootTag); }
AbstractXmlEntityHandler implements XmlEntityExportHandler<T> { protected static void appendEscapedXmlUtf8(final StringBuilder toAppendTo, final String text){ if (text != null) { for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); switch (c) { case '<': toAppendTo.append("&lt;"); break; case '>': toAppendTo.append("&gt;"); break; case '"': toAppendTo.append("&quot;"); break; case '\'': toAppendTo.append("&#039;"); break; case '&': toAppendTo.append("&amp;"); break; default: toAppendTo.append(c); } } } } protected  AbstractXmlEntityHandler(final String rootTag); @Override void startXml(final OutputStreamWriter writer); @Override void endXml(final OutputStreamWriter writer); void setPrettyPrint(final boolean prettyPrint); }
AbstractXmlEntityHandler implements XmlEntityExportHandler<T> { protected static void appendEscapedXmlUtf8(final StringBuilder toAppendTo, final String text){ if (text != null) { for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); switch (c) { case '<': toAppendTo.append("&lt;"); break; case '>': toAppendTo.append("&gt;"); break; case '"': toAppendTo.append("&quot;"); break; case '\'': toAppendTo.append("&#039;"); break; case '&': toAppendTo.append("&amp;"); break; default: toAppendTo.append(c); } } } } protected  AbstractXmlEntityHandler(final String rootTag); @Override void startXml(final OutputStreamWriter writer); @Override void endXml(final OutputStreamWriter writer); void setPrettyPrint(final boolean prettyPrint);  }