fix Xml String - Android XML

Android examples for XML:XML String

Description

fix Xml String

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String sValue = "java2s.com";
        System.out.println(fixXmlString(sValue));
    }/*from  www .jav a  2 s.c o  m*/

    public static String fixXmlString(String sValue) {
        // Change all unsafe XML characters into their safe ones
        String sReturnVal = sValue.replace("&", "&");
        sReturnVal = sReturnVal.replace("'", "'");
        sReturnVal = sReturnVal.replace("\"", """);
        sReturnVal = sReturnVal.replace("<", "&lt;");
        return sReturnVal.replace(">", "&gt;");
    }
}

Related Tutorials