escape XML Attribute Value - Android XML

Android examples for XML:XML String Escape

Description

escape XML Attribute Value

Demo Code


//package com.java2s;

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

    public static String escapeAttributeValue(String unescaped) {
        return escapeElementValue(unescaped); // TODO for now
    }

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

Related Tutorials