encode XML Entities - Android XML

Android examples for XML:XML Entity

Description

encode XML Entities

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String content = "java2s.com";
        System.out.println(encodeEntities(content));
    }// www .  j a  va2 s .c o  m

    public static String encodeEntities(String content) {
        content = content.replace("&", "&");
        content = content.replace("<", "&lt;");
        content = content.replace(">", "&gt;");
        content = content.replace("\"", "&quot;");
        content = content.replace("'", "&apos;");
        return content;
    }
}

Related Tutorials