Here you can find the source of escapeText(String rawText)
public static String escapeText(String rawText)
//package com.java2s; import java.text.CharacterIterator; import java.text.StringCharacterIterator; public class Main { /**/*from w w w . ja v a2 s . c om*/ * Escapes an XML string (i.e. <br/> * becomes <br/>) There are 5 entities of interest (<, >, ", ', and &) * * Unfortunately there are no built-in Java utilities for this, so we had to roll our own */ public static String escapeText(String rawText) { StringBuilder escapedText = new StringBuilder(); StringCharacterIterator characterIterator = new StringCharacterIterator( rawText); char currentCharacter = characterIterator.current(); while (currentCharacter != CharacterIterator.DONE) { switch (currentCharacter) { case '<': escapedText.append("<"); break; case '>': escapedText.append(">"); break; case '"': escapedText.append("""); break; case '\'': escapedText.append("'"); break; case '&': escapedText.append("&"); break; default: escapedText.append(currentCharacter); break; } currentCharacter = characterIterator.next(); } return escapedText.toString(); } }