unEscape XML String by replace - Java XML

Java examples for XML:XML String Escape

Description

unEscape XML String by replace

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String s = "java2s.com";
        System.out.println(unEscape(s));
    }//  ww w  .  j  a v a 2s  . c  o  m

    public static String unEscape(String s) {
        if (s == null) {
            return s;
        }
        return s.replaceAll("&amp;", "&").replaceAll("&lt;", "<")
                .replaceAll("&gt;", ">").replaceAll("&apos;", "'")
                .replaceAll("&quot;", "\"");
    }
}

Related Tutorials