Here you can find the source of unescapeFromXml(String escapedString)
Parameter | Description |
---|---|
escapedString | the string to un-escape |
public static String unescapeFromXml(String escapedString)
//package com.java2s; public class Main { /**/* ww w . j a va2 s . c o m*/ * Un-escape a string from its XML encoding - in particular, un-escape * &, <, >, ", and hex encoded characters. * @param escapedString the string to un-escape * @return the un-escaped string */ public static String unescapeFromXml(String escapedString) { StringBuffer string = new StringBuffer(); for (int c = 0; c < escapedString.length();) { char ch = escapedString.charAt(c); if (ch == '&') { if (escapedString.startsWith("amp;", (c + 1))) { string.append('&'); c += 5; } else if (escapedString.startsWith("lt;", (c + 1))) { string.append('<'); c += 4; } else if (escapedString.startsWith("gt;", (c + 1))) { string.append('>'); c += 4; } else if (escapedString.startsWith("quot;", (c + 1))) { string.append('"'); c += 6; } else if (escapedString.startsWith("apos;", (c + 1))) { string.append('\''); c += 6; } else if (escapedString.startsWith("#x", (c + 1))) { int sci = escapedString.indexOf(';', (c + 2)); if ((sci != -1) && (sci <= (c + 4))) try { ch = ((char) Integer.parseInt(escapedString.substring((c + 3), sci), 16)); c = sci; } catch (Exception e) { } string.append(ch); c++; } else if (escapedString.startsWith("#", (c + 1))) { int sci = escapedString.indexOf(';', (c + 1)); if ((sci != -1) && (sci <= (c + 4))) try { ch = ((char) Integer.parseInt(escapedString.substring((c + 2), sci))); c = sci; } catch (Exception e) { } string.append(ch); c++; } else if (escapedString.startsWith("x", (c + 1))) { int sci = escapedString.indexOf(';', (c + 1)); if ((sci != -1) && (sci <= (c + 4))) try { ch = ((char) Integer.parseInt(escapedString.substring((c + 2), sci), 16)); c = sci; } catch (Exception e) { } string.append(ch); c++; } else { string.append(ch); c++; } } else { string.append(ch); c++; } } return string.toString(); } }