Here you can find the source of unescapeXML(String str)
Parameter | Description |
---|---|
str | the string to un-escape |
public static String unescapeXML(String str)
//package com.java2s; //License from project: Apache License public class Main { /**/* w ww . ja v a2 s.c om*/ * Returns a string with XML entities replaced by their normal characters. * * @param str the string to un-escape * @return a new normal string */ public static String unescapeXML(String str) { if (str == null || str.length() == 0) return ""; StringBuilder buf = new StringBuilder(); int len = str.length(); for (int i = 0; i < len; ++i) { char c = str.charAt(i); if (c == '&') { int pos = str.indexOf(";", i); if (pos == -1) { // Really evil buf.append('&'); } else if (str.charAt(i + 1) == '#') { int val = Integer.parseInt(str.substring(i + 2, pos), 16); buf.append((char) val); i = pos; } else { String substr = str.substring(i, pos + 1); if (substr.equals("&")) buf.append('&'); else if (substr.equals("<")) buf.append('<'); else if (substr.equals(">")) buf.append('>'); else if (substr.equals(""")) buf.append('"'); else if (substr.equals("'")) buf.append('\''); else // ???? buf.append(substr); i = pos; } } else { buf.append(c); } } return buf.toString(); } }