escape XML Element Value - Android XML

Android examples for XML:XML String Escape

Description

escape XML Element Value

Demo Code


//package com.java2s;

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

    public static String escapeElementValue(String unescaped) {
        return unescaped.replace("&", "&amp;").replace("<", "&lt;")
                .replace(">", "&gt;").replace("'", "&apos;")
                .replace("\"", "&quot;");
    }
}

Related Tutorials