Here you can find the source of unescapeXML(String text)
public static String unescapeXML(String text)
//package com.java2s; //License from project: Open Source License public class Main { /** xml patterns that will be unescaped. Have to be the longest first */ private static String[] to_unescape = { "&nbsp;", "&mdash;", "&ndash;", "&", """, "'", "'", "—", "&ndash", " " }; private static char[] unescaped = { '\u0020', '\u2014', '\u2013', '&', '"', '\'', '\'', '\u2014', '\u2013', '\u0020' }; /** unescape a String in XML. . */ public static String unescapeXML(String text) { if (text.contains("&")) { StringBuilder result = new StringBuilder(text.length()); int n = text.length(); for (int i = 0; i < n; i++) { char c = text.charAt(i); if (c == '&') { for (int unescaped_index = 0; unescaped_index < to_unescape.length; unescaped_index++) { String pattern = to_unescape[unescaped_index]; boolean match = true; if (n <= i + pattern.length()) continue; for (int i_sub = 0; i_sub < pattern.length(); i_sub++) { if (text.charAt(i + i_sub) != pattern.charAt(i_sub)) { match = false; break; }/* ww w .j av a 2s .c om*/ } if (match) { result.append(unescaped[unescaped_index]); i += pattern.length() - 1; break; } } } else { result.append(c); } } return result.toString().trim(); } else return text.trim(); } }