List of utility methods to do XML String Escape
String | toXMLString(String s) to XML String StringBuffer stringbuffer = new StringBuffer(); for (int i = 0; s != null && i < s.length(); i++) { char c = s.charAt(i); if (c == '\'') stringbuffer.append("'"); else if (c == '"') stringbuffer.append("""); else if (c == '\n') ... |
String | xmlEscape(String xml) xml Escape return xml.replaceAll("&", "&").replaceAll("<", "<") .replaceAll(">", ">"); |
String | escape(String input) Useful to replace the characters forbidden in xml by their escaped counterparts Ex: & -> & return input.replace("&", "&").replace("<", "<") .replace(">", ">").replace("\"", """) .replace("\'", "'"); |
String | escapeText(String rawText) Escapes an XML string (i.e. StringBuilder escapedText = new StringBuilder(); StringCharacterIterator characterIterator = new StringCharacterIterator( rawText); char currentCharacter = characterIterator.current(); while (currentCharacter != CharacterIterator.DONE) { switch (currentCharacter) { case '<': escapedText.append("<"); ... |
String | getXmlEncoded(String text) get Xml Encoded StringBuffer buf = new StringBuffer(text); for (int i = 0; i < buf.length(); ++i) { char c = buf.charAt(i); if (c == '&') { buf.replace(i, i + 1, "&"); } else if (c == '<') { buf.replace(i, i + 1, "<"); } else if (c == '>') { ... |
String | encodeEntities(String content) encode Entities content = content.replace("&", "&"); content = content.replace("<", "<"); content = content.replace(">", ">"); content = content.replace("\"", """); content = content.replace("'", "'"); return content; |
String | encodeEntities(String content) encode Entities content = content.replace("&", "&"); content = content.replace("<", "<"); content = content.replace(">", ">"); content = content.replace("\"", """); content = content.replace("'", "'"); return content; |
String | encodeXML(final String str) encode XML final int max = str.length(); final StringBuffer buf = new StringBuffer(max + 10); for (int i = 0; i < max; ++i) final char c = str.charAt(i); switch (c) { case '&': buf.append("&"); ... |
String | XmlEscape(String value) Xml Escape if (value == null) return null; value = value.replaceAll("&", "&"); value = value.replaceAll("<", "<"); value = value.replaceAll(">", ">"); return value; |
String | xmlEscape(String source) Escape a string for use in XML. StringBuilder sb = new StringBuilder(source.length() + (source.length() / 10)); for (int i = 0; i < source.length(); i++) { char c = source.charAt(i); switch ("<>&'\"".indexOf(c)) { case 0: sb.append("<"); break; ... |