Here you can find the source of unescapeXMLString2(String str)
public static String unescapeXMLString2(String str)
//package com.java2s; //License from project: LGPL public class Main { public static String unescapeXMLString2(String str) { StringBuffer sb = new StringBuffer(); int index, last = 0, indexSemi; while ((index = str.indexOf('&', last)) != -1) { sb.append(str.substring(last, index)); indexSemi = str.indexOf(';', index + 1); if (indexSemi == -1) { sb.append('&'); last = index + 1;/*from w w w . j ava 2 s . co m*/ } else if (index + 1 == indexSemi) { sb.append("&;"); last = index + 2; } else { sb.append(unescapeXMLEntity(str.substring(index + 1, indexSemi))); last = indexSemi + 1; } } sb.append(str.substring(last)); return sb.toString(); } private static String unescapeXMLEntity(String str) { if ("lt".equals(str)) return "<"; if ("gt".equals(str)) return ">"; if ("amp".equals(str)) return "&"; if ("apos".equals(str)) return "'"; if ("quot".equals(str)) return "\""; return "&" + str + ";"; } }