XMLUtils { @Unstable public static String escapeElementText(String content) { if (content == null) { return null; } int contentLength = content.length(); StringBuilder result = new StringBuilder((int) (contentLength * 1.1)); for (int i = 0; i < contentLength; ++i) { char c = content.charAt(i); switch (c) { case '&': result.append(AMP); break; case '<': result.append(LT); break; default: result.append(c); } } return result.toString(); } private  XMLUtils(); static String extractXML(Node node, int start, int length); static String escapeXMLComment(String content); static String unescapeXMLComment(String content); @Deprecated static String escape(Object content); @Unstable static String escape(String content); @Deprecated static String escapeAttributeValue(Object content); @Unstable static String escapeAttributeValue(String content); @Unstable static String escapeElementText(String content); @Deprecated static String escapeElementContent(Object content); @Deprecated static String unescape(Object content); static Document createDOMDocument(); static Document parse(LSInput source); static String serialize(Node node); static String serialize(Node node, boolean withXmlDeclaration); static String transform(Source xml, Source xslt); static String formatXMLContent(String content);  }
@Test void escapeElementText() { String actual = XMLUtils.escapeElementText("a < a' && a' < a\" => a < a\""); assertEquals("a &#60; a' &#38;&#38; a' &#60; a\" => a &#60; a\"", actual); }
@Test void escapeElementTextNull() { assertNull(XMLUtils.escapeElementText(null)); }