Java XML Unescape unescapeXml(String value)

Here you can find the source of unescapeXml(String value)

Description

unescape Xml

License

Open Source License

Declaration

public static String unescapeXml(String value) 

Method Source Code

//package com.java2s;
/*//from w ww  .j  a  v  a2  s .  c  om
 * Copyright (C) 2006-2016 Talend Inc. - www.talend.com
 * 
 * This source code is available under agreement available at
 * %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
 * 
 * You should have received a copy of the agreement along with this program; if not, write to Talend SA 9 rue Pages
 * 92150 Suresnes, France
 */

public class Main {
    public static String unescapeXml(String value) {
        if (value != null) {
            StringBuilder result = new StringBuilder(value.length());
            int i = 0;
            int n = value.length();
            while (i < n) {
                char charAt = value.charAt(i);
                if (charAt != '&') {
                    result.append(charAt);
                    i++;
                } else {
                    if (value.startsWith("&amp;", i)) { //$NON-NLS-1$
                        result.append('&');
                        i += 5;
                    } else if (value.startsWith("&apos;", i)) { //$NON-NLS-1$
                        result.append('\'');
                        i += 6;
                    } else if (value.startsWith("&quot;", i)) { //$NON-NLS-1$
                        result.append('"');
                        i += 6;
                    } else if (value.startsWith("&lt;", i)) { //$NON-NLS-1$
                        result.append('<');
                        i += 4;
                    } else if (value.startsWith("&gt;", i)) { //$NON-NLS-1$
                        result.append('>');
                        i += 4;
                    }
                }
            }
            return result.toString().replaceAll("\t", "").replaceAll("\n", "").replaceAll("\r", ""); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$//$NON-NLS-6$
        } else {
            return null;
        }
    }
}

Related

  1. unescapeXML(String str)
  2. unescapeXml(String str)
  3. unescapeXML(String text)
  4. unescapeXML(String text)
  5. unescapeXml(String value)
  6. unescapeXml(String xml)
  7. unescapeXML(String xml)
  8. unescapeXmlChars(String source)
  9. unescapeXMLComment(String content)